-
Title Description:
-
Enter a positive integer n to output the factorial of N.
-
Input:
-
Positive integer N (0<=n<=1000)
-
Output:
-
Input may include multiple sets of data, for each set of input data, the factorial of the output n
-
Sample input:
-
4515
-
-
Sample output:
-
241201307674368000
#include <cstdio>#include<cstring>using namespacestd;Const intmaxn=10005;structbigint{intE[MAXN]; intLen; BigInt () {memset (E,0,sizeof(e)); Len=0; } BigInt (Long Longv) {memset (E,0,sizeof(e)); Len=0; while(v!=0) { intk=v%Ten; E[len++]=K; V/=Ten; }} BigIntoperator*(ConstBigInt &t)Const{BigInt res; for(intI=0; i<len;i++) { intup=0; for(intj=0; j<t.len;j++) { intz=e[i]*t.e[j]+up+res.e[i+J]; Res.e[i+j]=z%Ten; up=z/Ten; } if(up!=0) {Res.e[i+t.len]=Up ; }} Res.len=len+T.len; while(res.len>1&&res.e[res.len-1]==0) res.len--; returnRes; } voidprint () { for(inti=len-1; i>=0; i--) printf ("%d", E[i]); printf ("\ n"); }}res[1005];intMain () {intN; res[0].e[0]=1; res[0].len=1; for(intI=1; i<= +; i++) {BigInt T (i); Res[i]=res[i-1]*T; } while(SCANF ("%d", &n)! =EOF) {Res[n].print (); } return 0;}
2006 Tsinghua: Factorial of N