#include<bits/stdc++.h> usingnamespacestd; #define MAXN 100 constdouble PI = acos(-1); /*快速傅立叶变换*/ structFastFourierTransform { /*复数*/ complex<double> omega[MAXN], omegaInverse[MAXN]; inlinevoidinit(constint n){ for (registerint i = 0; i < n; i++) { omega[i] = complex<double>(cos(2 * PI / n * i), sin(2 * PI / n * i)); /*conj函数可以返回一个复数的共轭复数*/ omegaInverse[i] = conj(omega[i]); } } inlinevoidtransform(complex<double> *a, constint n, constcomplex<double> *omega){ int k = 0; while ((1 << k) < n) k++; for (registerint i = 0; i < n; i++) { int t = 0; for (registerint j = 0; j < k; j++) if (i & (1 << j)) t |= (1 << (k - j - 1)); if (i < t) swap(a[i], a[t]); } for (registerint l = 2; l <= n; l *= 2) { int m = l / 2; for (complex<double> *p = a; p != a + n; p += l) { for (int i = 0; i < m; i++) { complex<double> t = omega[n / l * i] * p[m + i]; p[m + i] = p[i] - t; p[i] += t; } } } } inlinevoiddft(complex<double> *a, constint n){ transform(a, n, omega); } inlinevoididft(complex<double> *a, constint n){ transform(a, n, omegaInverse); for (registerint i = 0; i < n; i++) a[i] /= n; } } fft; inlinevoidmultiply(constint *a1, constint n1, constint *a2, constint n2, int *res){ int n = 1; while (n < n1 + n2) n <<= 1; staticcomplex<double> c1[MAXN], c2[MAXN]; for (registerint i = 0; i < n1; i++) c1[i].real(a1[i]); for (registerint i = 0; i < n2; i++) c2[i].real(a2[i]); fft.init(n); fft.dft(c1, n), fft.dft(c2, n); for (registerint i = 0; i < n; i++) c1[i] *= c2[i]; fft.idft(c1, n); for (registerint i = 0; i < n1 + n2 - 1; i++) res[i] = static_cast<int>(floor(c1[i].real() + 0.5)); } intmain(){ return0; }