-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva623.cpp
64 lines (53 loc) · 1.11 KB
/
uva623.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
#include <cstdio>
#include <cstring>
#include <cmath>
const int MAXN = 1001;
typedef struct CBIN {
int num[3000];
int size;
CBIN() {
size = 1;
memset(num, 0, sizeof(num));
}
} cbint;
cbint dp[1100];
cbint mult_bint(cbint arr, int n) {
int carry = 0;
cbint newbint;
newbint.size = arr.size;
for(int i = 0; i < arr.size; ++i) {
int value = arr.num[i] * n + carry;
newbint.num[i] = value % 10;
carry = value / 10;
}
while (carry != 0) {
newbint.size++;
newbint.num[newbint.size - 1] = carry%10;
carry /= 10;
}
return newbint;
}
void build_dp() {
cbint a, b;
dp[0].num[0] = 1;
dp[1].num[0] = 1;
for (int i = 2; i < MAXN; ++i) {
dp[i] = mult_bint(dp[i - 1], i);
}
}
void print_bint(int n) {
for(int i = dp[n].size - 1; i >= 0; --i) {
printf("%d", dp[n].num[i]);
}
printf("\n");
}
int main () {
// freopen("input.txt", "r", stdin);
int n;
build_dp();
while(scanf("%d", &n) != EOF) {
printf("%d!\n", n);
print_bint(n);
}
return 0;
}