structComplex{ double x, y; const Complex operator +(const Complex &t)const{ return (Complex){x + t.x, y + t.y}; } const Complex operator -(const Complex &t)const{ return (Complex){x - t.x, y - t.y}; } const Complex operator *(const Complex &t)const{ return (Complex){x * t.x - y * t.y, x * t.y + y * t.x}; } }a[N], b[N]; int tot, bit, rev[N];
voidFFT(Complex a[], int inv) { for (int i = 0; i < tot; ++ i) if (rev[i] < i) swap(a[rev[i]], a[i]);
for (int mid = 1; mid < tot; mid <<= 1) { Complex w1 = (Complex){cos(PI / mid), sin(inv * PI / mid)}; for (int i = 0; i < tot; i += mid * 2) { Complex now = (Complex){1, 0}; for (int j = 0; j < mid; j ++, now = now * w1) { Complex x = a[i + j], y = now * a[i + j + mid]; a[i + j] = x + y, a[i + j + mid] = x - y; } } } }
intmain() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i <= n; ++ i) scanf("%lf", &a[i].x); for (int i = 0; i <= m; ++ i) scanf("%lf", &b[i].x);
while ((1 << bit) < n + m + 1) bit ++; tot = 1 << bit;
for (int i = 0; i < tot; ++ i) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << bit - 1);
FFT(a, 1);FFT(b, 1); for (int i = 0; i < tot; ++ i) a[i] = a[i] * b[i]; FFT(a, -1);
for (int i = 0; i <= n + m; ++ i) printf("%d ", int((a[i].x / tot) + 0.5));
Gitalking ...