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
-
-
The code is as follows
-
#include <iostream> #define N 200000using namespace Std;int number[n];void creat () { number[0] = 1;  ; for (int i = 1; i < N; i + +) Number[i] = 0;} int m (int n) { creat (); int result_size = 1; int carrybit = 0; if (n = = 1) return result_size; for (int i = 2; I <= n; i + +) { for (int j = 0; J < Result_size; J + +) { &NB Sp int temp = number[j] * i + carrybit; NUMBER[J] = temp% 10; & nbsp Carrybit = temp/10; } while (carrybit! = 0) &NB Sp { number[result_size] = carrybit% 10; & nbsp Result_size ++; &NBsp Carrybit = carrybit/10; } } return result_size;} void print () { int n; CIN >> n; int t = m (n); for (int i = t-1; I >= 0; I--) cout << number[i]; cout << Endl; int main () { print (); return 0;}
Large number factorial