码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 1042 大数阶乘

时间:2016-08-16 17:32:13      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

B - 2
Time Limit:5000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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


代码:

#include<stdio.h>
#include<string.h>
#define N 11000

void pp(int a[],int num)
{
int i;
for(i = 0;i < N;i++)
a[i] = a[i] * num;

for(i = 0;i < N;i++)
{
a[i+1] += a[i] / 10000;
a[i] = a[i] % 10000;
}
}
void put(int a[])
{
int i=N-1;

while(!a[i])
i--;
printf("%d",a[i]);

for(i--;i>=0;i--)
printf("%04d",a[i]);

}
int main()
{
int a[N];
int n,i;
while(scanf("%d",&n) != EOF)
{
memset(a,0,sizeof(a));
a[0]=1;
for(i=1;i<=n;i++)
{
pp(a,i);
}

put(a);
printf("\n");
}
return 0;
}

HDU 1042 大数阶乘

标签:

原文地址:http://www.cnblogs.com/dll6/p/5777145.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!