标签:
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 66786 Accepted Submission(s):
19147
1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 int main() 5 { 6 int i,j,n,k,s,m,t; 7 int a[100005]; //保存n! 8 while(~scanf("%d",&n)) 9 { 10 a[0]=1; 11 s=1; //记录数组的位数 12 for(i=1; i<=n; i++) 13 { 14 k=0; //记录进位的值 15 for(j=0; j<s; j++) //每一位都要乘以i 16 { 17 t=a[j]*i+k; 18 a[j]=t%10; //只保留个位数 19 k=t/10; //去掉最后一位 20 } 21 while(k) //将k的值全部压入数组 22 { 23 a[s++]=k%10; 24 k/=10; 25 } 26 } 27 for(i=s-1; i>=0; i--) //注意倒着输出 28 printf("%d",a[i]); 29 printf("\n"); 30 } 31 return 0; 32 }
标签:
原文地址:http://www.cnblogs.com/pshw/p/4813381.html