-
Notifications
You must be signed in to change notification settings - Fork 0
/
10220.cpp
47 lines (38 loc) · 892 Bytes
/
10220.cpp
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <cstdio>
#include <cstring>
using namespace std;
#define BASE 1000000000000000
int sum[1001];
int main(void)
{
int len, i, j, n;
long list[1000], tmpL;
memset(sum, 0, sizeof(int) * 1001);
memset(list, 0, sizeof(long) * 1000);
sum[0] = 0;
sum[1] = 1;
sum[2] = 2;
sum[3] = 6;
list[0] = 6;
len = 1;
for (i = 4; i < 1001; ++i) {
for (j = 0; j < len; ++j)
list[j] *= i;
for (j = 0; j < len; ++j) {
list[j + 1] += list[j] / BASE;
list[j] %= BASE;
}
while (list[len] > 0)
++len;
for (j = 0; j < len; ++j) {
tmpL = list[j];
while (tmpL > 0) {
sum[i] += tmpL % 10;
tmpL /= 10;
}
}
}
while (scanf("%d", &n) != EOF)
printf("%d\n", sum[n]);
return 0;
}