//一个n项和一个m项求卷积
typedef long long LL;
const int p = 998244353, G = 3, Gi = 332748118;//这里的Gi是G的除法逆元
const int N = 5000007;
const double PI = acos(-1);
int n, m;
int res, ans[N];
int len = 1;//
int L;//二进制的位数
int RR[N];
LL a[N], b[N];
inline int qread()
{
int x = 0, y = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
y = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * y;
}
LL ksm(LL a, LL b, LL p)
{
LL ans = 1;
while (b) {
if (b & 1) ans = ans * a % p;
b >>= 1;
a = a * a % p;
}
return ans;
}
LL inv(LL x) { return ksm(x, p - 2, p); }
void NTT(LL* A, int type)
{
for (int i = 0; i < len; ++i)
if (i < RR[i])
swap(A[i], A[RR[i]]);
for (int mid = 1; mid < len; mid <<= 1) {
LL wn = ksm(G, (p - 1) / (mid * 2), p);
if (type == -1) wn = ksm(wn, p - 2, p);
//如果超时了上面if这句话删掉,在下面的if(type == -1)里加上下面这个循环
/*for (int i = 1; i < len / 2; i ++)
swap(A[i], A[len - i]); */
for (int j = mid << 1, pos = 0; pos < len; pos += j) {
LL w = 1;
for (int k = 0; k < mid; ++k, w = (w * wn) % p) {
int x = A[pos + k], y = w * A[pos + mid + k] % p;
A[pos + k] = (x + y) % p;
A[pos + k + mid] = (x - y + p) % p;
}
}
}
if (type == -1) {
LL limit_inv = inv(len);
for (int i = 0; i < len; ++i)
A[i] = (A[i] * limit_inv) % p;
}
}
void poly_mul(LL* a, LL* b, int deg)//多项式乘法
{
for (len = 1, L = 0; len <= deg; len <<= 1) L++;
for (int i = 0; i < len; ++i) {
RR[i] = (RR[i >> 1] >> 1) | ((i & 1) << (L - 1));
}
NTT(a, 1);
NTT(b, 1);
for (int i = 0; i < len; ++i) a[i] = a[i] * b[i] % p;
NTT(a, -1);
}
int main()
{
n = qread(), m = qread();
for (int i = 0; i <= n; ++i) a[i] = (qread() + p) % p;//取模
for (int i = 0; i <= m; ++i) b[i] = (qread() + p) % p;
poly_mul(a, b, n + m);
for (int i = 0; i <= n + m; ++i)
printf("%d ", a[i]);
return 0;
}
附带原根表
3 | 1 | 1 | 2 |
5 | 1 | 2 | 2 |
17 | 1 | 4 | 3 |
97 | 3 | 5 | 5 |
193 | 3 | 6 | 5 |
257 | 1 | 8 | 3 |
7681 | 15 | 9 | 17 |
12289 | 3 | 12 | 11 |
40961 | 5 | 13 | 3 |
65537 | 1 | 16 | 3 |
786433 | 3 | 18 | 10 |
5767169 | 11 | 19 | 3 |
7340033 | 7 | 20 | 3 |
23068673 | 11 | 21 | 3 |
104857601 | 25 | 22 | 3 |
167772161 | 5 | 25 | 3 |
469762049 | 7 | 26 | 3 |
998244353 | 119 | 23 | 3 |
1004535809 | 479 | 21 | 3 |
2013265921 | 15 | 27 | 31 |
2281701377 | 17 | 27 | 3 |
3221225473 | 3 | 30 | 5 |
75161927681 | 35 | 31 | 3 |
77309411329 | 9 | 33 | 7 |
206158430209 | 3 | 36 | 22 |
2061584302081 | 15 | 37 | 7 |
2748779069441 | 5 | 39 | 3 |
6597069766657 | 3 | 41 | 5 |
39582418599937 | 9 | 42 | 5 |
79164837199873 | 9 | 43 | 5 |
263882790666241 | 15 | 44 | 7 |
1231453023109121 | 35 | 45 | 3 |
1337006139375617 | 19 | 46 | 3 |
3799912185593857 | 27 | 47 | 5 |
4222124650659841 | 15 | 48 | 19 |
7881299347898369 | 7 | 50 | 6 |
31525197391593473 | 7 | 52 | 3 |
180143985094819841 | 5 | 55 | 6 |
1945555039024054273 | 27 | 56 | 5 |
4179340454199820289 | 29 | 57 | 3 |