阶乘之和-魏国

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;
#define M 10000
int t[90],ans[90],n,strent=1,strena=1,o;
int main()
{
cin>>n;
t[1]=1; 
for(int i=1;i<=n;i++)
{
o=0;
for(int j=1;j<=strent;j++)
{    
long long p=i*t[j]+o;
t[j]=p%M;
o=p/M;
if(o&&j==strent)    {t[++strent]=o;break;}
}
o=0;
for(int j=1;j<=strena;j++)
{    
ans[j]+=t[j];
o=ans[j]/M;
ans[j+1]+=o;
ans[j]%=M;
if(o&&j==strena)    {strena++;break;}
}
}    
printf("%d ",ans[strena]);
for(int i=strena-1;i>=1;i--)
printf("%04d ",ans[i]);
return 0;
}

 

一直没过

一个没过的样例

22

11 7765 2997 4434 2894 0313

posted @ 2017-03-17 16:25  浪矢-CL  阅读(166)  评论(0编辑  收藏  举报