N!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 57220 Accepted Submission(s): 16213
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(极光炫影)
/*
忙里偷闲。。。。水一题以前做过好多次,不过没在杭电oj提交过
Time:2014-11-26 7:27
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX=50000;
int main(){
int N,i,j;
int a[MAX];
while(scanf("%d",&N)!=EOF){
memset(a,0,sizeof(a));
int digit=1,t=0;a[0]=1;
for(i=1;i<=N;i++){
for(j=0;j<=digit;j++){
t=t+a[j]*i;
a[j]=t%10;
t/=10;
if(t>0&&j+2>digit){
digit++;
}
}
}
while(a[digit]==0)digit--;
for(i=digit;i>=0;i--){
printf("%d",a[i]);
}
puts("");
}
return 0;
}