N!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 43815 Accepted Submission(s): 12316
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(极光炫影)
#include<iostream>
using namespace std;
#define nn 8001
int main()
{
int n;
while(~scanf("%d",&n))
{
int i,j,a[nn];
memset(a,0,sizeof(a));
a[0]=1;
for(i=2;i<=n;i++)
{
int c=0;
for(j=0;j<nn;j++)
{
int s=a[j]*i+c;
a[j]=s%100000;//每五个数放在一个字符里
c=s/100000;
}
}
for(i=nn-1;i>=0;i--)
if(a[i])
break;
printf("%d",a[i]);//第一个数可能不满5个所以直接输出
for(j=i-1;j>=0;j--)
printf("%05d",a[j]);//1以后字符里的5个数里可能包含0要注意输出格式加%05d
printf("\n");
}
return 0;
}