hdu1042——N!

来源:互联网 发布:免费换ip软件 编辑:程序博客网 时间:2024/04/30 07:46

N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 69704    Accepted Submission(s): 19958


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
 算了下N的阶乘,为复习一下期末考试,诶!
#include<iostream>#include<cstdio>using namespace std;void fac(int);int main(){int n;while(scanf("%d",&n)!=EOF){fac(n);printf("\n");}return 0;}inline void fac(int n){long long a[100000];int i,j,c,m=0;a[0]=1;for(i=1;i<=n;i++){c=0;for(j=0;j<=m;j++){a[j]=a[j]*i+c;c=a[j]/10;a[j]%=10;}while(c>0){a[++m]=c%10;c/=10;}}for(i=m;i>=0;i--)printf("%d",a[i]);} 

0 0
原创粉丝点击