N!
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
#include<stdio.h>
#include<cstring>
int s[100008];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(s,0,sizeof s);
s[0]=1;
int i,j,it,p=1;
for(i=2;i<=n;i++)
{
it=0;
for(j=0;j<p;j++)
{
s[j]=s[j]*i+it;
it=s[j]/100000;
s[j]=s[j]%100000;
}
if(it)
{
p++;
s[p-1]=s[p-1]+it;
}
}
printf("%d",s[p-1]);
for(i=p-2;i>=0;i--)
{
printf("%05d",s[i]);
}
printf("\n");
}
return 0;
}
就是循环进位,5个一进.