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

HDU 1042 N!(大数阶乘)

时间:2015-07-24 20:21:09      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

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

 

Sample Output
1
2
6
 
代码:
 1 #include<cstdio>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     int i,n,digit,temp,carry,j;
 7     int a[40005];
 8     while(scanf("%d",&n)!=EOF)
 9     {
10         a[0]=1;
11         digit=0;
12         for(i=2;i<=n;i++)
13         {
14             for(carry=0,j=0;j<=digit;j++)
15             {
16                 temp=a[j]*i+carry;
17                 a[j]=temp%10;
18                 carry=temp/10;
19             }
20             while(carry)
21             {
22                 a[++digit]=carry%10;
23                 carry/=10;
24             }
25         }
26         for(i=digit;i>=0;i--)
27         printf("%d",a[i]);
28         printf("\n");
29     }
30     return 0;
31 } 

 

HDU 1042 N!(大数阶乘)

标签:

原文地址:http://www.cnblogs.com/homura/p/4674235.html

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