算阶乘,最蠢的就是竟然有把10000组全部存下来的想法...
1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 int ans[10000],tmp,n,len; 5 int main() 6 { 7 while(~scanf("%d",&n)) 8 { 9 memset(ans,0,sizeof(ans)); 10 len=ans[1]=1; 11 for(int i=1;i<=n;i++) 12 { 13 tmp=0; 14 for(int j=1;j<=len;j++) 15 { 16 ans[j]=ans[j]*i+tmp; 17 tmp=ans[j]/10000; 18 ans[j]%=10000; 19 } 20 while(tmp) 21 { 22 ans[++len]=tmp%10000; 23 tmp/=10000; 24 } 25 } 26 printf("%d",ans[len]); 27 for(int i=len-1;i>0;i--) printf("%04d",ans[i]); 28 puts(""); 29 } 30 }