Posted on 2009-04-29 16:15
superman 阅读(178)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 freopen("fact4.in", "r", stdin);
8 freopen("fact4.out", "w", stdout);
9
10 int n, c2 = 0, c5 = 0, cr = 1;
11
12 cin >> n;
13
14 for (int i = 2; i <= n; i++)
15 {
16 int t = i;
17
18 while (t && t % 2 == 0) c2++, t /= 2;
19 while (t && t % 5 == 0) c5++, t /= 5;
20
21 cr *= t, cr %= 10;
22 }
23
24 for (int i = 0; i < c2 - c5; i++)
25 cr *= 2, cr %= 10;
26
27 cout << cr << endl;
28
29 return 0;
30 }
31