-
Notifications
You must be signed in to change notification settings - Fork 3
/
H2.cpp
161 lines (139 loc) · 3.14 KB
/
H2.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
// https://codeforces.com/contest/1916/problem/H2
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef vector<ull> vu;
typedef pair<ull, ull> uu;
typedef vector<uu> vuu;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<bool> vb;
#define fore(i, a, b) for (ull i = a, gmat = b; i < gmat; i++)
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()
#define DBG(x) cerr << #x << " = " << x << endl
const ull inf = 1ull << 60;
// Based on ModularArithmetic of kactl
constexpr ull mod = 998244353;
struct Mod {
ull x;
Mod(ull xx) : x(xx % mod) {}
Mod() : x(0) {}
Mod operator+(Mod b) const {
return Mod((x + b.x) >= mod ? x + b.x - mod : x + b.x);
}
Mod operator-(Mod b) const {
return Mod(x >= b.x ? x - b.x : x + mod - b.x);
}
Mod operator*(Mod b) const {
return Mod((x * b.x) % mod);
}
Mod operator+=(Mod b) {
return *this = *this + b;
}
Mod operator-=(Mod b) {
return *this = *this - b;
}
Mod operator*=(Mod b) {
return *this = *this * b;
}
Mod operator++() {
return *this = *this + Mod(1);
}
Mod operator--() {
return *this = *this - Mod(1);
}
bool operator==(Mod b) const {
return x == b.x;
}
bool operator!=(Mod b) const {
return x != b.x;
}
bool operator<(Mod b) const {
return x < b.x;
}
bool operator>(Mod b) const {
return x > b.x;
}
bool operator<=(Mod b) const {
return x <= b.x;
}
bool operator>=(Mod b) const {
return x >= b.x;
}
Mod invert(Mod a) const {
Mod r = a ^ (mod - 2);
return r;
}
Mod operator^(ull e) const {
Mod r = Mod(1);
Mod b = *this;
while (e > 0) {
if (e & 1) {
r *= b;
}
b *= b;
e /= 2;
}
return r;
}
Mod operator/(Mod b) const {
return *this * invert(b);
}
Mod operator/=(Mod b) {
return *this = *this / b;
}
friend ostream& operator<<(ostream& os, Mod m) {
os << m.x;
return os;
}
friend istream& operator>>(istream& is, Mod& m) {
is >> m.x;
return is;
}
operator ull() const {
return x;
}
operator ll() const {
return x;
}
};
typedef vector<Mod> vm;
vm solve(ull n, ull p, ull k) {
vm p_pow(k + 1, 1);
fore(i, 1, k + 1) {
p_pow[i] = p_pow[i - 1] * Mod(p);
}
Mod pn = Mod(p) ^ n;
vector<Mod> pnpj2(k + 1);
fore(j, 0, k + 1) {
Mod pnpj = pn - p_pow[j];
pnpj2[j] = pnpj * pnpj;
}
vm ans(k + 1), nums(k + 1), dens(k + 1);
ans[0] = nums[0] = dens[0] = 1;
fore(r, 1, k + 1) {
nums[r] = nums[r - 1] * pnpj2[r - 1];
dens[r] = dens[r - 1] * p_pow[r - 1] * (p_pow[r] - Mod(1));
if (dens[r].x > 0) {
ans[r] = nums[r] / dens[r];
} else if (nums[r].x == 0) {
ans[r] = 0;
} else {
ans[r] = 1;
}
}
return ans;
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
ull n, p, k;
cin >> n >> p >> k;
vm ans = solve(n, p, k);
for (Mod a : ans) {
cout << a << ' ';
}
cout << '\n';
return EXIT_SUCCESS;
}