poj 求10000以内的N的阶乘的和

#include<iostream>
using namespace std;
int a[100000]={0};
int main()
{
 int n;
 int i,len=1,j,temp=0;
 cin>>n;
 a[0]=1;
 for(i=2;i<=n;i++)
 {
  for(j=0;j<len;j++)
  {
   a[j]=i*a[j]+temp;
   temp=a[j]/10;
   a[j]%=10;
  }
  while(temp!=0)
  {
   a[j++]=temp%10;
   temp/=10;
  }
  len=j;
 }
 len+=50-len%50;
 for(i=len-1;i>=0;i--)
 {
  if((i+1)%50==0&&i+1!=len)
  cout<<"\n";
  cout<<a[i];
 }
 cout<<"\n";
 return 0;
}

posted @ 2012-04-07 13:50  逝者*恋世  阅读(238)  评论(0编辑  收藏  举报