1 #include <cstdio>
2 #include <algorithm>
3 #include <cstring>
4 using namespace std;
5 unsigned short s[20000];//最多可以容纳5000阶乘;且必须为int型,当为short型时,数组元素大小溢出。因为c为int型,当不段的
6 int main()
7 {
8 int m;
9 while(~scanf("%d",&m))
10 {
11 memset(s,0,sizeof(s));
12 s[0]=1;
13 int c,l=0;
14 for(int i=1;i<=m;i++)//m的阶乘
15 {
16 c=0;
17 for(int j=0;j<=20000;j++)//乘以i之后结果
18 {
19 s[j]=s[j]*i+c;
20 c=s[j]/10;
21 s[j]%=10;
22 }
23 }
24 //printf("%d",s[l]);
25 int i;
26 for(i=20000;i>=0;i--)
27 if(s[i])
28 break;
29 for(;i>=0;i--)
30 printf("%d",s[i]);
31 printf("\n");
32 }
33 return 0;
34 }