HDU 1042 N!

来源:互联网 发布:大字体软件老人 编辑:程序博客网 时间:2024/05/16 20:28

N!


Problem Description

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

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

Output
For each N, output N! in one line.
 

Sample Input
123
 

Sample Output
126


大数阶乘!!

#include <iostream>using namespace std;int a[55555];int main(){int n,i,j;while(scanf("%d",&n)!=EOF){memset(a,0,sizeof(a));if(n==0||n==1){printf("1\n");continue;}int l=1;a[0]=1;for(i=2;i<=n;i++){for(j=0;j<l;j++)a[j]*=i;for(j=0;j<l;j++){if(a[j]>9){a[j+1]+=a[j]/10;a[j]%=10;if(j==l-1)l++;}}}for(i=l-1;i>=0;i--)printf("%d",a[i]);printf("\n");}return 0;}


 

原创粉丝点击