forked from chenzuoyuan/KaoyanOnlineJudge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1076N的阶乘.cpp
69 lines (67 loc) · 1.23 KB
/
1076N的阶乘.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
题目描述:
输入一个正整数N,输出N的阶乘。
输入:
正整数N(0<=N<=1000)
输出:
输入可能包括多组数据,对于每一组输入数据,输出N的阶乘
样例输入:
4
5
15
样例输出:
24
120
1307674368000
*/
#include <stdio.h>
#include <string.h>
struct bigInteger{
int digit[1000];
int size;
void init(){
for(int i=0;i<1000;i++) digit[i]=0;
size=0;
}
void set(int x){
init();
do{
digit[size++]=x%10000;
x/=10000;
}while(x!=0);
}
void output(){
for(int i=size-1;i>=0;i--){
if(i!=size-1) printf("%04d",digit[i]);
else printf("%d",digit[i]);
}
printf("\n");
}
bigInteger operator * (int x) const {
bigInteger ret;
ret.init();
int carry=0;
for(int i=0;i<size;i++){
int tmp=x*digit[i]+carry;
carry=tmp/10000;
tmp%=10000;
ret.digit[ret.size++]=tmp;
}
if(carry!=0){
ret.digit[ret.size++]=carry;
}
return ret;
}
}a;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
a.init();
a.set(1);
for(int i=1;i<=n;i++){
a=a*i;
}
a.output();
}
return 0;
}