Large number factorial time limit:MS | Memory limit:65535 KB Difficulty:3
-
Describe
-
we all know how to calculate the factorial of a number, but if the number is large, how do we calculate it and output it?
-
Input
-
Enter an integer m (0<m<=5000)
-
Output
-
The factorial of the output m and enter a newline character after the output ends
-
Sample input
-
50
-
Sample output
-
30414093201713378043612608166064768844377641568960512000000000000
-
Code
1 //NYOJ-28 large number factorial2 //directly open an array large enough to simulate a vertical operation, carry. 3#include <cstdio>4#include <cstring>5 Const intMAXN =20000;6 intF[MAXN];7 intMain () {8 inti,j,n,s,c;9scanf"%d", &n);TenMemset (F,0,sizeof(f)); Onef[0] =1; A for(i =2; I <= N; i++) { -c =0; - //Rounding the for(j =0; J < Maxn; J + +) { -s = f[j] * i +C; -F[J] = s%Ten; -c = S/Ten; + } - } + for(j = maxn-1; J >=0; j--)if(F[j]) Break; A for(i = j; I >=0; i--) printf ("%d", F[i]); atprintf"\ n"); - return 0; -}
"Large number factorial" NYOJ-28