USACO Factorials

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
ID: wcr19961
PROG: fact4
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
freopen("fact4.in", "r", stdin);
freopen("fact4.out", "w", stdout);
int n, ans = 1;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
ans *= i;
while (ans % 10 == 0) {
ans /= 10;
}
ans %= 100000;
}
printf("%d\n", ans % 10);
return 0;
}

支付宝扫码领红包