-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcao HP.txt
149 lines (138 loc) · 2.44 KB
/
cao HP.txt
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
const int N = 110, M = 125;
int n;
int f[N][M], ttt[M];
void addHH(int a[], int b[])
{
static int c[M];
memset(c, 0, sizeof c);
for(int i = 0, t = 0; i < M; i ++)
{
t += a[i] + b[i];
c[i] = t % 10;
t /= 10;
}
memcpy(a, c, sizeof c);
}
void mul1(int res[], int a[], int b)
{
static int c[M];
memset(c, 0, sizeof c);
for(int i = 0, t = 0; i < M; i ++)
{
t += a[i] * b;
c[i] = t % 10;
t /= 10;
}
memcpy(res, c, sizeof c);
}
void mul2(int res[], int a[], int b[])
{
static int c[M];
memset(c, 0, sizeof c);
for(int i = 0; i < M / 2; i ++)
for(int j = 0; j < M / 2; j ++)
c[i + j] += a[i] * b[j];
for(int i = 0, t = 0; i < M; i ++)
{
t += c[i];
c[i] = t % 10;
t /= 10;
}
memcpy(res, c, sizeof c);
}
void hpprint(int a[])
{
int k = M - 1;
while(k >= 0 && !a[k]) k --;
while(k >= 0) printf("%d", a[k --]);
}
int main()
{
f[0][0] = 1, f[1][0] = 1;
for(int i = 2; i <= 100; i ++)
for(int j = 0; j < i; j ++)
{
mul2(ttt, f[j], f[i - j - 1]);
add(f[i], ttt);
}
// for(int i = 1; i <= 100; i ++)
// {
// printf("f[%d] = ", i);
// hpprint(f[n]);
// puts("");
// }
int T = 0;
while(cin >> n, n != -1)
{
mul1(ttt, f[n], 2);
printf("%d %d ", ++ T, n);
hpprint(ttt);
puts("");
}
return 0;
}
void addHL(int a[], int b, int res[])
{
static int c[M];
memset(c, 0, sizeof c);
int t = b;
for(int i = 0; i < M; i ++)
{
t += a[i];
c[i] = t % 10;
t /= 10;
}
memcpy(res, c, sizeof c);
}
void mulHL(int a[], int b, int res[])
{
static int c[M];
memset(c, 0, sizeof c);
int t = 0;
for(int i = 0; i < M; i ++)
{
t += a[i] * b;
c[i] = t % 10;
t /= 10;
}
memcpy(res, c, sizeof c);
}
void mulHH(int a[], int b[], int res[])
{
static int c[M];
memset(c, 0, sizeof c);
for(int i = 0; i < M; i ++)
for(int j = 0; j < M; j ++)
c[i + j] += a[i] * b[j];
int t = 0;
for(int i = 0; i < M; i ++)
{
t += c[i];
c[i] = t % 10;
t /= 10;
}
memcpy(res, c, sizeof c);
}
int cmpHH(int a[], int b[])
{
for(int i = M - 1; i >= 0; i --)
{
if(a[i] > b[i]) return 1;
if(a[i] < b[i]) return -1;
}
return 0;
}
void printH(int a[])
{
int k = M - 1;
while(k > 0 && !a[k]) k --;
for(int i = k; i >= 0; i --)
printf("%d", a[i]);
puts("");
}