14: Ask for the factorial of the N within 10000
-
Total time limit:
-
5000ms
-
Memory Limit:
-
655360kB
-
Describe
-
Ask for a factorial of 10000 or less n.
-
Input
-
Only one line of input, integer n (0<=n<=10000).
-
Output
-
A row, which is the value of n!.
-
Sample input
-
100
-
Sample output
-
9332621544394415268169923885626670049071596826438162146859296389521759999322991560894146397615651828625369792082722375825 1185210916864000000000000000000000000
-
Source
-
JP06
Ideas:
Simulation
Come on, on the code:
#include <cstdio>using namespacestd;intN,len,cur=1, s[500010];intMain () {scanf ("%d",&N); Len=0; s[0]=1; for(intv=2; v<=n;v++) { for(intI=0; i<=len;i++) s[i]*=v; Cur=0; for(intI=0; i<=len;i++) {S[i]+=cur; Cur=0; if(s[i]>9) cur+=s[i]/Ten; S[i]%=Ten; } while(cur>0) s[++len]=cur%Ten, cur/=Ten; } for(inti=len;i>=0; i--) Putchar (s[i]+'0'); return 0;}
AC Diary--10000 n factorial openjudge 1.6 14