所谓高精度

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <string.h>
//jie cheng
struct bigInteger
{
int digit[1000];
int size;
void init()
{
for(int i=0;i<1000;i++)
digit[i]=0;
size=0;
}

void set(int x) //solve N! N is a small int
{
init();
do
{
digit[size++]=x%10000;
x/=10000;
}while(x);
}

void output()
{
for(int i=size-1;i>=0;i--)
{
if(i!=size-1) printf("%04d",digit[i]);
else printf("%d",digit[i]);
}
printf("\n");
}

bigInteger operator * (const int &x) const
{
bigInteger ret;
ret.init();
int carry=0;
for(int i=0;i<size;i++)
{
int temp=x*digit[i]+carry;
carry=temp/10000;
temp%=10000;
ret.digit[ret.size++]=temp;
}
if(carry!=0)
{
ret.digit[ret.size++]=carry;
}
return ret;
}

bigInteger operator + (const bigInteger &A) const
{
bigInteger ret;
ret.init();
int carry=0;
for(int i=0;i<A.size||i<size;i++)
{
int temp=A.digit[i]+digit[i]+carry;
carry=temp/10000;
temp%=10000;
ret.digit[ret.size++]=temp;
}
if(carry!=0)
ret.digit[ret.size++]=carry;

return ret;
}
}a;

int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
a.init();
a.set(1);
for(int i=1;i<=n;i++)
{
a=a*i;
}
a.output();
}
return 0;
}