14: Calculate the factorial of n less than 10000, And the factorial of 1410000
14: Calculate the factorial of n less than 10000
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
5000 ms
-
Memory limit:
-
655360kB
-
Description
-
Calculate the factorial of n less than 10000.
-
Input
-
Only one line of input, integer n (0 <=n <= 10000 ).
-
Output
-
One row, that is, n! .
-
Sample Input
-
100
-
Sample output
-
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
-
Source
-
JP06
-
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 using namespace std; 6 int a[1000001]={1}; 7 int ans[10000001]={1}; 8 char n[1001]; 9 int en[1001];10 int main()11 {12 int n;13 cin>>n;14 int lans=1;15 int x=0;16 for(int i=1;i<=n;i++)17 {18 19 for(int j=0;j<lans;j++)20 {21 a[j]=a[j]*i+x;22 x=a[j]/10;23 if(x>0&&j==lans-1)24 lans++;25 a[j]=a[j]%10;26 }27 }28 int flag=0;29 for(int i=lans;i>=0;i--)30 {31 if(a[i]==0&&flag==0)32 continue;33 else flag=1;34 cout<<a[i];35 }36 return 0;37 }