-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.cpp
177 lines (144 loc) · 3.7 KB
/
B.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <iostream>
#include <vector>
const long long MOD = 998244353LL;
const int SIZE = 101;
size_t n, m;
std::vector<long long> expCoefs;
std::vector<long long> logCoefs;
std::vector<long long> sqrtCoefs;
long long gcdex(long long a, long long b, long long& x, long long& y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
long long x1, y1;
long long d = gcdex(b % a, a, x1, y1);
x = (y1 - ((b / a) * x1));
y = x1;
return d;
}
long long reverseElement(long long a, long long M) {
long long x, y, d;
d = gcdex(a, M, x, y);
if (d != 1) {
return 1;
} else {
return (x % M + M) % M;
}
}
long long getInversed(long long a) {
return reverseElement(a, MOD);
}
void calcExpCoefs() {
expCoefs.resize(SIZE + 1);
expCoefs[0] = 1;
for (int i = 1; i <= 100; i++) {
expCoefs[i] = expCoefs[i - 1];
expCoefs[i] *= getInversed(i);
expCoefs[i] %= MOD;
}
}
void calcLogCoefs() {
logCoefs.resize(SIZE + 1);
logCoefs[1] = 1;
for (int i = 2; i <= 100; i++) {
logCoefs[i] = -logCoefs[i - 1] + MOD;
logCoefs[i] %= MOD;
logCoefs[i] *= (i - 1);
logCoefs[i] %= MOD;
logCoefs[i] *= getInversed(i);
logCoefs[i] %= MOD;
}
}
void calcSqrtCoefs() {
sqrtCoefs.resize(SIZE + 1);
sqrtCoefs[0] = 1;
for (int i = 1; i <= 100; i++) {
sqrtCoefs[i] = -sqrtCoefs[i - 1] + MOD;
sqrtCoefs[i] %= MOD;
sqrtCoefs[i] *= ((2 * i - 1) * (2 * i) * (3 - 2 * i) + MOD) % MOD;
sqrtCoefs[i] %= MOD;
sqrtCoefs[i] *= getInversed((i * i * 4 * (1 - 2 * i) + MOD) % MOD);
sqrtCoefs[i] %= MOD;
}
}
std::vector<std::vector<long long>> PPows;
std::vector<long long> multiply(const std::vector<long long>& A, const std::vector<long long>& B) {
std::vector<long long> res(SIZE);
for (int i = 0; i < res.size(); ++i) {
long long mul = 0;
for (int j = 0; j <= i; ++j) {
mul = (mul + (A[j] * B[i - j] % MOD)) % MOD;
}
res[i] = mul;
}
return res;
}
void calcPow(const std::vector<long long>& A) {
for (int i = 2; i <= 100; ++i) {
PPows.push_back(multiply(A, PPows[i - 1]));
}
}
void exp(int size) {
for (int i = 0; i < size; ++i) {
long long coef = 0;
for (int j = 0; j < size; ++j) {
long long coefJI = expCoefs[j] * PPows[j][i];
coefJI %= MOD;
coef += coefJI;
coef %= MOD;
}
std::cout << coef << " ";
}
}
void log(int size) {
for (int i = 0; i < size; ++i) {
long long coef = 0;
for (int j = 0; j < size; ++j) {
long long coefJI = logCoefs[j] * PPows[j][i];
coefJI %= MOD;
coef += coefJI;
coef %= MOD;
}
std::cout << coef << " ";
}
}
void sqrt(int size) {
for (int i = 0; i < size; ++i) {
long long coef = 0;
for (int j = 0; j < size; ++j) {
long long coefJI = sqrtCoefs[j] * PPows[j][i];
coefJI %= MOD;
coef += coefJI;
coef %= MOD;
}
std::cout << coef << " ";
}
}
int main() {
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
std::cin >> n >> m;
calcExpCoefs();
calcLogCoefs();
calcSqrtCoefs();
std::vector<long long> P(SIZE);
std::vector<long long> E(SIZE);
E[0] = 1;
for (int i = 0; i <= n; ++i) {
long long coef;
std::cin >> coef;
P[i] = coef;
}
PPows.push_back(E);
PPows.push_back(P);
calcPow(P);
sqrt(m);
std::cout << "\n";
exp(m);
std::cout << "\n";
log(m);
std::cout << "\n";
return 0;
}