HDU 1042 N!
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
高精度处理,用字符串来存储。
#include"iostream"
using namespace std;
char ans[35661];//10000的时候是35660位数
int main()
{
int n;
while(cin>>n)
{
int i,digit=1;
ans[0]=1;
for(i=2;i<=n;i++)
{
int j,k;
for(j=k=0;j<digit;j++)
{
int temp=ans[j]*i+k;
ans[j]=temp%10;
k=temp/10;
}
while(k)
{
ans[digit++]=k%10;
k/=10;
}
}
for(i=digit-1;i>=0;i--)
printf("%d",ans[i]);
cout<<endl;
}
return 0;
}
浙公网安备 33010602011771号