fft裸题 我还没有背下来fft
#include<bits/stdc++.h> #define pi acos(-1) using namespace std; const int N = 300010; int n, m, L, x; int r[N]; complex<double> a[N], b[N]; void fft(complex<double> *a, int f) { for(int i = 0; i < n; ++i) if(i < r[i]) swap(a[i], a[r[i]]); for(int i = 1; i < n; i <<= 1) { complex<double> t(cos(pi / i), f * sin(pi / i)); for(int p = i << 1, j = 0; j < n; j += p) { complex<double> w(1, 0); for(int k = 0; k < i; ++k, w *= t) { complex<double> x = a[j + k], y = w * a[j + k + i]; a[j + k] = x + y; a[j + k + i] = x - y; } } } } int main() { scanf("%d%d", &n, &m); for(int i = 0; i <= n; ++i) scanf("%d", &x), a[i] = x; for(int i = 0; i <= m; ++i) scanf("%d", &x), b[i] = x; m = n + m; for(n = 1; n <= m; n <<= 1) ++L; for(int i = 0; i < n; ++i) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (L - 1)); fft(a, 1); fft(b, 1); for(int i = 0; i <= n; ++i) a[i] = a[i] * b[i]; fft(a, -1); for(int i = 0; i <= m; ++i) printf("%d ", (int)(a[i].real() / n + 0.5)); return 0; }