2022-11-27 13:40:45 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cmath>
|
|
|
|
#include <complex>
|
2022-11-28 13:31:18 +00:00
|
|
|
#include <valarray>
|
2022-11-27 13:40:45 +00:00
|
|
|
|
|
|
|
using std::cin;
|
|
|
|
using std::cout;
|
|
|
|
const char endl = '\n';
|
|
|
|
|
|
|
|
const double PI = std::acos(-1);
|
|
|
|
|
2022-11-28 13:31:18 +00:00
|
|
|
void fast_fourier_transform(std::valarray<std::complex<double>>& a) {
|
2022-11-27 13:40:45 +00:00
|
|
|
if (a.size() == 1) return;
|
|
|
|
|
2022-11-30 07:26:26 +00:00
|
|
|
// assert(a.size() == 1 << std::__lg(a.size()));
|
|
|
|
int k = std::__lg(a.size());
|
2022-11-27 13:40:45 +00:00
|
|
|
|
2022-11-30 07:26:26 +00:00
|
|
|
for (int i = 0; i < a.size(); i++) {
|
|
|
|
int t = 0;
|
2022-11-27 13:40:45 +00:00
|
|
|
|
2022-11-30 07:26:26 +00:00
|
|
|
for (int j = 0; j < k; j++) {
|
|
|
|
if (i & (1 << j)) {
|
|
|
|
t |= 1 << (k - j - 1);
|
|
|
|
}
|
|
|
|
}
|
2022-11-27 13:40:45 +00:00
|
|
|
|
2022-11-30 07:26:26 +00:00
|
|
|
if (i < t) std::swap(a[i], a[t]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int len = 2; len <= a.size(); len <<= 1) {
|
|
|
|
std::complex<double> wlen(std::cos(2 * PI / len), std::sin(2 * PI / len));
|
|
|
|
|
|
|
|
for (int i = 0; i < a.size(); i += len) {
|
|
|
|
std::complex<double> w(1);
|
|
|
|
|
|
|
|
for (int j = 0; j < len / 2; j++) {
|
|
|
|
std::complex<double> u = a[i + j],
|
|
|
|
v = a[i + j + len / 2] * w;
|
|
|
|
|
|
|
|
a[i + j] = u + v;
|
|
|
|
a[i + j + len / 2] = u - v;
|
|
|
|
w *= wlen;
|
|
|
|
}
|
|
|
|
}
|
2022-11-27 13:40:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
std::ios::sync_with_stdio(false);
|
|
|
|
cin.tie(nullptr);
|
|
|
|
|
|
|
|
int n, m;
|
|
|
|
|
|
|
|
cin >> n >> m;
|
|
|
|
|
|
|
|
int k = 1 << (std::__lg(n + m) + 1);
|
2022-11-28 13:31:18 +00:00
|
|
|
std::valarray<std::complex<double>> f(k), g(k);
|
2022-11-27 13:40:45 +00:00
|
|
|
|
|
|
|
for (int i = 0; i <= n; i++) {
|
|
|
|
cin >> f[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i <= m; i++) {
|
|
|
|
cin >> g[i];
|
|
|
|
}
|
|
|
|
|
2022-11-28 13:31:18 +00:00
|
|
|
fast_fourier_transform(f);
|
|
|
|
fast_fourier_transform(g);
|
2022-11-27 13:40:45 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < k; i++) {
|
|
|
|
f[i] *= g[i];
|
|
|
|
}
|
|
|
|
|
2022-11-28 13:31:18 +00:00
|
|
|
fast_fourier_transform(f);
|
|
|
|
std::reverse(std::begin(f) + 1, std::end(f));
|
2022-11-27 13:40:45 +00:00
|
|
|
|
|
|
|
for (int i = 0; i <= n + m; i++) {
|
|
|
|
cout << static_cast<int>(std::round(f[i].real() / k)) << ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|