普通的阶乘模拟肯定是不行的,需要按位对阶乘还有乘法过程进行模拟。
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1042
#include<stdio.h>
#include<string.h>
#define maxn 50000
int f[maxn];
int main()
{
int i,j,n;
while(scanf("%d",&n)!=EOF)
{
memset(f,0,sizeof(f));
f[0]=1;
int count=1;
for(i=1; i<=n; i++)
{
int c=0;//进位
for(j=0; j<count; j++)//阶乘位数
{
int s=f[j]*i+c;
f[j]=s%10;
c=s/10;
}
while(c)
{
f[count++]=c%10;
c/=10;
}
}
for(j=maxn-1; j>=0; j--)
if(f[j]) break;
for(i=j; i>=0; i--)
printf("%d",f[i]);
printf("\n");
}
return 0;
}