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 <cstring> 2 #include <cstdio> 3 #include <iostream> 4 #include <algorithm> 5 #include <cmath> 6 #include <stack> 7 #include <vector> 8 #include <queue> 9 #include <cmath> 10 using namespace std; 11 #define N 10005 12 typedef long long LL; 13 void jiec(int a[],int num) 14 { 15 int i; 16 for(i=0;i<N;i++) 17 a[i] = a[i] * num; 18 19 for(i=0;i<N;i++) 20 { 21 a[i+1] += a[i] / 10000; 22 a[i] = a[i] % 10000; 23 } 24 } 25 void put(int a[]) 26 { 27 int i = N-1; 28 29 while(!a[i]) i--; 30 printf("%d",a[i]); 31 32 for(i--;i>=0;i--) 33 printf("%04d",a[i]); 34 35 printf(" "); 36 } 37 int main() 38 { 39 int n; 40 int a[N]; 41 while(scanf("%d", &n)!=EOF) 42 { 43 memset(a,0,sizeof(a)); 44 45 a[0] = 1; 46 47 for(int i=1; i<=n; i++) 48 jiec(a,i); 49 50 put(a); 51 52 } 53 return 0; 54 }