总时间限制: 5000ms 内存限制: 655360kB
描述
求10000以内n的阶乘。
输入只有一行输入,整数n(0<=n<=10000)。输出一行,即n!的值。样例输入
100
样例输出
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
来源http://noi.openjudge.cn/ch0106/14/
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 int a[100000],n,i,y,xy[100000]; 5 6 int main() 7 { 8 cin>>n; 9 a[0]=1; 10 a[1]=1; 11 for (y=1;y<=n;y++) 12 { 13 memset(xy,0,sizeof(xy)); 14 xy[0]=a[0]; 15 for (i=1;i<=a[0];i++) 16 { 17 xy[i]+=a[i]*y; 18 xy[i+1]=xy[i]/10; 19 xy[i]%=10; 20 } 21 while (xy[xy[0]+1]>0) 22 { 23 xy[xy[0]+2]=xy[xy[0]+1]/10; 24 xy[xy[0]+1]%=10; 25 xy[0]++; 26 } 27 for (i=1;i<=xy[0];i++) a[i]=xy[i]; 28 a[0]=xy[0]; 29 } 30 for (i=a[0];i>=1;i--) cout<<a[i]; 31 cout<<endl; 32 return 0; 33 }