2022-11-27 13:45:56 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using std::cin;
|
|
|
|
using std::cout;
|
|
|
|
const char endl = '\n';
|
|
|
|
|
2022-12-01 13:00:00 +00:00
|
|
|
const int mod = 998244353;
|
2022-11-27 13:45:56 +00:00
|
|
|
|
2022-12-01 13:00:00 +00:00
|
|
|
constexpr long long binpow(long long a, long long b) {
|
|
|
|
a %= mod;
|
2022-11-27 13:45:56 +00:00
|
|
|
|
2022-12-01 13:00:00 +00:00
|
|
|
long long res = 1;
|
2022-11-27 13:45:56 +00:00
|
|
|
|
2022-12-01 13:00:00 +00:00
|
|
|
while (b) {
|
|
|
|
if (b & 1) res = res * a % mod;
|
|
|
|
a = a * a % mod;
|
|
|
|
b >>= 1;
|
2022-11-27 13:45:56 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 13:00:00 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2022-12-02 08:40:22 +00:00
|
|
|
void number_theoretic_transform(std::vector<long long> &a) {
|
|
|
|
if (a.size() == 1) return;
|
|
|
|
|
2022-12-01 13:00:00 +00:00
|
|
|
// assert(a.size() == (1 << std::__lg(a.size())));
|
|
|
|
int k = std::__lg(a.size());
|
2022-11-27 13:45:56 +00:00
|
|
|
|
2022-12-01 13:00:00 +00:00
|
|
|
for (int i = 0; i < a.size(); i++) {
|
|
|
|
int t = 0;
|
2022-11-27 13:45:56 +00:00
|
|
|
|
2022-12-01 13:00:00 +00:00
|
|
|
for (int j = 0; j < k; j++) {
|
|
|
|
if (i & (1 << j)) {
|
|
|
|
t |= 1 << (k - j - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < t) std::swap(a[i], a[t]);
|
2022-11-27 13:45:56 +00:00
|
|
|
}
|
2022-12-01 13:00:00 +00:00
|
|
|
|
|
|
|
for (int len = 2; len <= a.size(); len <<= 1) {
|
|
|
|
int m = len >> 1;
|
|
|
|
long long wn = binpow(3, (mod - 1) / len);
|
|
|
|
|
|
|
|
for (int i = 0; i < a.size(); i += len) {
|
|
|
|
long long w = 1;
|
|
|
|
|
|
|
|
for (int j = 0; j < m; j++) {
|
|
|
|
long long u = a[i + j],
|
|
|
|
v = a[i + j + m] * w % mod;
|
|
|
|
|
|
|
|
a[i + j] = ((u + v) % mod + mod) % mod;
|
|
|
|
a[i + j + m] = ((u - v) % mod + mod) % mod;
|
|
|
|
w = w * wn % mod;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-27 13:45:56 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 13:00:00 +00:00
|
|
|
class Poly : public std::vector<long long> {
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
using std::vector<long long>::vector;
|
|
|
|
|
|
|
|
Poly() = default;
|
|
|
|
|
|
|
|
Poly(const std::vector<long long> &__v)
|
|
|
|
: std::vector<long long>(__v) {}
|
|
|
|
|
|
|
|
Poly(std::vector<long long> &&__v)
|
|
|
|
: std::vector<long long>(std::move(__v)) {}
|
|
|
|
|
|
|
|
Poly operator*(const Poly &b) const {
|
|
|
|
int n = size() - 1,
|
|
|
|
m = b.size() - 1,
|
|
|
|
k = 1 << (std::__lg(n + m) + 1),
|
|
|
|
inv = binpow(k, mod - 2);
|
|
|
|
|
|
|
|
std::vector<long long> f(*this), g(b);
|
|
|
|
|
|
|
|
f.resize(k);
|
2022-12-02 08:40:22 +00:00
|
|
|
number_theoretic_transform(f);
|
2022-12-01 13:00:00 +00:00
|
|
|
g.resize(k);
|
2022-12-02 08:40:22 +00:00
|
|
|
number_theoretic_transform(g);
|
2022-12-01 13:00:00 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < k; i++) {
|
|
|
|
f[i] = f[i] * g[i] % mod;
|
|
|
|
}
|
|
|
|
|
2022-12-02 08:40:22 +00:00
|
|
|
number_theoretic_transform(f);
|
2022-12-01 13:00:00 +00:00
|
|
|
// assert(f.size() > 0)
|
|
|
|
std::reverse(f.begin() + 1, f.end());
|
|
|
|
|
|
|
|
std::vector<long long> res(n + m + 1);
|
|
|
|
|
|
|
|
for (int i = 0; i <= n + m; i++) {
|
|
|
|
res[i] = f[i] * inv % mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Poly(res);
|
|
|
|
}
|
|
|
|
} poly;
|
|
|
|
|
2022-11-27 13:45:56 +00:00
|
|
|
int main() {
|
|
|
|
std::ios::sync_with_stdio(false);
|
|
|
|
cin.tie(nullptr);
|
|
|
|
|
|
|
|
int n, m;
|
|
|
|
|
|
|
|
cin >> n >> m;
|
|
|
|
|
2022-12-01 13:00:00 +00:00
|
|
|
Poly f(n + 1), g(m + 1);
|
2022-11-27 13:45:56 +00:00
|
|
|
|
|
|
|
for (int i = 0; i <= n; i++) {
|
|
|
|
cin >> f[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i <= m; i++) {
|
|
|
|
cin >> g[i];
|
|
|
|
}
|
|
|
|
|
2022-12-01 13:00:00 +00:00
|
|
|
auto res = f * g;
|
2022-11-27 13:45:56 +00:00
|
|
|
|
2022-12-01 13:00:00 +00:00
|
|
|
for (int x : res) cout << x << ' ';
|
2022-11-27 13:45:56 +00:00
|
|
|
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|