mcomplex () {} mcomplex (double fx, double fy) : x (fx), y (fy) {}
mcomplex operator + (const mcomplex& p) const { return mcomplex (x + p.x, y + p.y); } mcomplex operator - (const mcomplex& p) const { return mcomplex (x - p.x, y - p.y); } mcomplex operator * (const mcomplex& p) const { return mcomplex (x * p.x - y * p.y, x * p.y + y * p.x); } } ; mcomplex omega(int n, int k, int inv){ return mcomplex (cos (2.0 * PI * (double) k / (double) n), 1.0 * inv * sin (2.0 * PI * (double) k / (double) n)); } mcomplex A[MAXN], B[MAXN];
voidFFT(mcomplex* a, int n, int inv){ if (n == 1) return ; mcomplex a1[n >> 1], a2[n >> 1]; int m = n >> 1; for (int i = 0; i <= n; i += 2) { a1[i >> 1] = a[i]; a2[i >> 1] = a[i + 1]; } FFT (a1, m, inv); FFT (a2, m, inv); for (int i = 0; i < m; i ++) { mcomplex x = omega (n, i, inv); a[i] = a1[i] + x * a2[i]; a[i + m] = a1[i] - x * a2[i]; } }
intgetnum(){ int num = 0; char ch = getchar ();
while (! isdigit (ch)) ch = getchar (); while (isdigit (ch)) num = (num << 3) + (num << 1) + ch - '0', ch = getchar ();
return num; }
intmain(){ N = getnum (), M = getnum (); for (int i = 0; i <= N; i ++) A[i].x = (double) getnum (); for (int i = 0; i <= M; i ++) B[i].x = (double) getnum ();
int n; for (n = 1; n <= N + M; n <<= 1); FFT (A, n, 1); FFT (B, n, 1); for (int i = 0; i <= n; i ++) A[i] = A[i] * B[i]; FFT (A, n, - 1); for (int i = 0; i <= N + M; i ++) { if (i) putchar (' '); printf ("%d", (int) (A[i].x / n + 0.5)); } puts ("");
mcomplex () {} mcomplex (double fx, double fy) : x (fx), y (fy) {}
mcomplex operator + (const mcomplex& p) const { return mcomplex (x + p.x, y + p.y); } mcomplex operator - (const mcomplex& p) const { return mcomplex (x - p.x, y - p.y); } mcomplex operator * (const mcomplex& p) const { return mcomplex (x * p.x - y * p.y, x * p.y + y * p.x); } } ; mcomplex omega(int n, int k, int inv){ return mcomplex (cos (2.0 * PI * (double) k / (double) n), 1.0 * inv * sin (2.0 * PI * (double) k / (double) n)); } mcomplex A[MAXN], B[MAXN];
int oppo[MAXN]; int limit; voidFFT(mcomplex* a, int inv){ for (int i = 0; i < limit; i ++) if (i < oppo[i]) swap (a[i], a[oppo[i]]); for (int mid = 1; mid < limit; mid <<= 1) { mcomplex ome = mcomplex (cos (PI / (double) mid), inv * sin (PI / (double) mid)); for (int n = mid << 1, j = 0; j < limit; j += n) { mcomplex x = mcomplex (1, 0); for (int k = 0; k < mid; k ++, x = x * ome) { mcomplex a1 = a[j + k], xa2 = x * a[j + k + mid]; a[j + k] = a1 + xa2; a[j + k + mid] = a1 - xa2; } } } }
intgetnum(){ int num = 0; char ch = getchar ();
while (! isdigit (ch)) ch = getchar (); while (isdigit (ch)) num = (num << 3) + (num << 1) + ch - '0', ch = getchar ();
return num; }
intmain(){ N = getnum (), M = getnum (); for (int i = 0; i <= N; i ++) A[i].x = (double) getnum (); for (int i = 0; i <= M; i ++) B[i].x = (double) getnum ();
int n, lim = 0; for (n = 1; n <= N + M; n <<= 1, lim ++); for (int i = 0; i <= n; i ++) oppo[i] = (oppo[i >> 1] >> 1) | ((i & 1) << (lim - 1)); limit = n; 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 <= N + M; i ++) { if (i) putchar (' '); printf ("%d", (int) (A[i].x / n + 0.5)); } puts ("");