HDU_1042——阶乘,万进制

 1 #include <cstdio>
 2 const int MAX = 10000;
 3 const int BASE = MAX;
 4 int main()
 5 {
 6     int n, i, j;
 7     while(~scanf("%d",&n))
 8         {
 9             int ans[10000]={0}, left=MAX-1, t=0;
10             ans[MAX-1]=1;
11             for(i=2;i<=n;i++)
12                 {
13                     for(j=MAX-1;j>=left;j--)
14                         {
15                             ans[j] = ans[j]*i + t;
16                             t = ans[j]/BASE;
17                             ans[j] = ans[j]%BASE;
18                         }
19                     if(t)
20                         {
21                             left--;
22                             ans[left]=t;
23                             t=0;
24                         }
25                 }
26             for(i=0;ans[i]==0;i++);
27             printf("%d",ans[i]);
28             for(i++;i<MAX;i++)
29                 {
30                     printf("%04d",ans[i]);
31                 }
32             printf("\n");
33         }
34     return 0;
35 }

 

posted @ 2013-07-15 09:18  瓶哥  Views(351)  Comments(0Edit  收藏  举报