-
Description
-
We all know how to calculate a factorial of a number. But if this number is large, how should we calculate it and output it?
-
Input
-
Enter an integer m (0 <m <= 5000)
-
Output
-
Output the factorial of M, and enter a linefeed after the output ends.
Analysis: the number of obvious factorial is relatively large, and INT overflow occurs. Therefore, the int array method is used to store each bit with array elements. According to the multiplication rule, use each bit of the array element to multiply and iterate
# Include <iostream> # include <cstring> # include <cstdlib> using namespace STD; int main () {int arr [20000]; memset (ARR, 0, sizeof (ARR); int m; int COUNT = 0; CIN> m; arr [0] = 1; for (INT I = 2; I <= m; I ++) {for (Int J = 0; j <20000; j ++) {COUNT = arr [J] * I + count; arr [J] = count % 10; Count = count/10;} int I; for (I = 20000-1 ;! Arr [I]; I --); For (; I> = 0; I --) {cout <arr [I] ;}cout <Endl; return 0 ;}
[Click quiz 28] Big Data factorial