Large number factorial time limit: theMs | Memory Limit:65535KB 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
-
-
-
-
#include <stdio.h> #include <string.h> #include <string> #include <math.h># Include <stdlib.h> #include <iostream> #include <algorithm> #include <vector> #include < queue> #include <set> #include <map> #include <queue> #include <stack>using namespace Std;int A[10000];int Main () {int n;while (~scanf ("%d", &n) {int digit=1;int res,sum;int i,j,k;a[0]=1;for (i=2;i<=n;i++) { for (res=0,j=1;j<=digit;j++) {SUM=A[J-1]*I+RES;A[J-1]=SUM%10;RES=SUM/10;} while (res) {digit++;a[digit-1]=res%10;res/=10;}} for (k=digit;k>=1;k--) {printf ("%d", a[k-1]);} Cout<<endl;}
return 0;}
-
-
nyoj-28-large number factorial