http://www.luogu.org/problem/show?pid=1009
高精度答案:
#include <iostream>
#include <cstring>
using namespace std;
int az[100],bz[100],q,k;
int main()
{
cin >>q;
az[0]=1;
for (int y=1;y<=q;y++)
{
for (int p=1;p<=y;p++)
{
for (int i=0;i<99;i++)
az[i]*=p;
for(int u=0;u<99;u++)
if (az[u]>9){
az[u+1]+=az[u]/10;
az[u]%=10;
}
}
for (int i=0;i<100;i++)
{
bz[i]+=az[i];
if (bz[i]>9){
bz[i+1]++;bz[i]-=10;
}
az[i]=0;
}
az[0]=1;
}
for (int i=99;i>0;i--)
{
if(bz[i]==0&&k==0)
continue;
k=1;
cout <<bz[i];
}
cout <<bz[0];
return 0;
}
低精度:
#include <stdio.h>
int main(int argc, char *argv[])
{
int a,b;
int i=1,j=1;
int sum=0;
scanf("%d",&a);
for(i=1;i<=a;i++)
{
b=1;
for(j=1;j<=i;j++)
{
b=b*j;
}
sum+=b;
}
//int 只支持到a=26
printf("%d",sum);
return 0;
}