G.cpp 386 B

1234567891011121314151617181920
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int n;
  5. cin >> n;
  6. int s = 1;
  7. int two = 0, five = 0;
  8. for (int i = 2; i <= n; i++) {
  9. int j = i;
  10. while (j % 2 == 0)j /= 2, ++two;
  11. while (j % 5 == 0)j /= 5, ++five;
  12. s = (s * j) % 10;
  13. }
  14. two -= five;
  15. while (two--)s = (s * 2) % 10;
  16. cout << s << endl;
  17. return 0;
  18. }