hdu 1042 N!
N!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 44897 Accepted Submission(s): 12748
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
Author
JGShining(极光炫影)
//984MS 288K 618 B C++ //大数阶乘,你懂的 #include<stdio.h> #include<string.h> #define N 100000 int a[10005]; void init(int n) { memset(a,0,sizeof(a)); a[0]=1; int temp=0; for(int i=2;i<=n;i++){ for(int j=0;j<10001;j++){ temp+=a[j]*i; a[j]=temp%N; temp/=N; } } } int main(void) { int n; while(scanf("%d",&n)!=EOF) { init(n); int i=10000; while(!a[i]) i--; //printf("%d\n",i); printf("%d",a[i--]); for(int j=i;j>=0;j--) printf("%05d",a[j]); printf("\n"); } return 0; }