1042/72 n!
Problem Description
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
Input
One N in one line, process to the end of file.
Output
For each N, output N! in one line.
Sample Input
1
2
3
Sample Output
1
2
6
1 #include <iostream> 2 #include <algorithm> 3 #include <stdio.h> 4 #include <math.h> 5 #include <string.h> 6 #include <time.h> 7 using namespace std; 8 int a[10001]; 9 int main() 10 { 11 int n,sum,i,j,k; 12 while(~scanf("%d",&n)) 13 { 14 k=a[0]=1;sum=0; 15 for(i=n;i>1;i--) 16 { 17 for(j=0;j<k;j++) 18 { 19 a[j]=a[j]*i+sum; 20 sum=a[j]/100000; 21 a[j]=a[j]%100000; 22 23 } 24 while(sum) 25 { 26 a[k++]=sum%100000; 27 sum=sum/100000; 28 } 29 } 30 cout<<a[k-1]; 31 for(int i=k-2;i>=0;i--) 32 printf("%05d",a[i]); 33 cout<<endl; 34 } 35 return 0; 36 }
这个题有两个知识点:
1.数值型高精度
2.补零操作(重点)