# N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25136    Accepted Submission(s): 6967

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
1 2 3

Sample Output
1 2 6

Author
JGShining（极光炫影）

Statistic | Submit | Discuss | Note

#include <stdio.h>

int main()
{
int n;
while(scanf("%d",&n)==1)
{
int a[9000]={1};
int i,len=1,j;
for(i=2;i<=n;i++)
{
for(j=0;j<len;j++)
{
a[j]*=i;
}

for(j=0;j<len-1;j++)
{
a[j+1]+=a[j]/10000;
a[j]%=10000;
}

if(a[len-1]>10000)
{
a[len]=a[len-1]/10000;
a[len-1]%=10000;
len++;
}
}
printf("%d",a[len-1]);
for(i=len-2;i>=0;i--)
{
printf("%04d",a[i]);
}
printf("\n");
}
return 0;
}

#### HDU1042的代码

2014年05月02日 862B 下载

#### HDU-1042-N!(Java大法好 && HDU大数水题)

2015-06-10 10:38:40

#### HDU 1042 N! (大数阶乘,紫书上的方法超时!!还是Java大法好!!)

2016-05-12 23:00:04

#### hdu1042-N!(大数)

2015-08-20 16:33:10

#### HDU1042 n!【大数＋万进制】

2016-05-29 09:50:44

#### HDU1042 N! 万进制

2012-04-08 14:34:25

#### HDU1042

2015-09-21 13:45:43

#### hdu1042 N!

2014-03-21 19:11:07

#### hdu1042【大数阶乘】

2017-02-07 16:23:58

#### hdu1042大数阶乘

2012-12-11 13:15:13