HDU_1042

发个体母链接:    http://acm.hdu.edu.cn/showproblem.php?pid=1042

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<memory.h>
 4 using namespace std;
 5 #define MAX 10000
 6 #define BASE 100000
 7 int h[MAX];
 8
 9
10 int main()
11 {
12     int i,j,k,carry;
13     int n;
14
15     while(scanf("%d",&n)!=EOF)
16     {
17         memset(h,0,MAX*sizeof(int));
18         h[MAX-1]=1;
19
20         for(i=1;i<=n;i++)
21         {
22             carry=0;//表示进位
23
24             for(k=MAX-1;k>=0;k++)
25             {
26                 carry=carry+i*h[k];
27                 h[k]=carry%BASE;
28                 carry=carry/BASE;
29             }
30
31             for(j=MAX;j<MAX&&j==0;j--)
32             {
33                 printf("%d",h[j++]);
34             }
35             for(;j<MAX;++j)
36             {
37                 printf("%05d",h[j]);
38             }
39             printf("\n");
40          }
41
42     }
43
44     return 0;
45 }
时间: 2024-12-18 14:26:19

HDU_1042的相关文章

hdu_1042(模拟大数乘法)

计算n! 1 #include<cstring> 2 #include<cstdio> 3 using namespace std; 4 int num[50000]; 5 int main() 6 { 7 int n; 8 while(~scanf("%d",&n)) 9 { 10 memset(num,0,sizeof(num)); 11 int len = 1; 12 num[1] = 1; 13 for(int i = 2; i <= n;

杭电HDU_1042

ps:刚才重打了这段代码,之前的有错 #include <iostream> #include<cstdio> using namespace std; #define MAX 10000 #define BASE 100000//基度可以选不同的值 ,eg:80000 int h[MAX];//10000大小的数组 int main() { int i,j,k,carry; int n; while(scanf("%d",&n)!=EOF) { mem