N!

来源:互联网 发布:镇江淘宝模特兼职招聘 编辑:程序博客网 时间:2024/05/18 04:44


http://acm.hdu.edu.cn/showproblem.php?pid=1042

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int a[8010];
int main()
{
// freopen("C:\\Users\\John\\Desktop\\hi.txt","r",stdin);
 int n;
 int i=1;
 while(cin>>n)
 {
  int k=0,j;
  memset(a,0,sizeof(a));
  a[1]=1;
  for(j=1;j<=n;j++)
  {
   for(i=1;i<=8000;i++)
   {
    a[i]=a[i]*j+k;
    k=a[i]/100000;
    a[i]%=100000;
   }
   
  }
  for(i=8000;;i--)
  if(a[i]!=0)
  break;
  cout<<a[i];
  i--;
  for(;i>=1;i--)
  printf("%05d",a[i]);
  cout<<endl;
 }
 return 0;
}

0 0
原创粉丝点击