大数阶乘

来源:互联网 发布:awscli json 编辑:程序博客网 时间:2024/04/28 18:09

大数阶乘

 


Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! 

One N in one line, process to the end of file. 

For each N, output N! in one line. 

#include<stdio.h>#include<string.h>const int MAX=10005,M=100000000;long long a[MAX];int main(){int n,g,k,b,c;while(scanf("%d",&g)!=EOF){b=0;memset(a,0,sizeof(a));a[0]=1;for(int i=1;i<=g;i++){for(c=k=0;k<=b;k++)a[k]=i*a[k]+c,c=a[k]/M,a[k]%=M;b=k-(c&&(a[k]=c)?0:1);}printf("%lld",a[b]);while(b--)printf("%0.8lld",a[b]);printf("\n");}return 0;}


0 0
原创粉丝点击