inlineintGc(){ return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2)? EOF: *p1++; } template<typename T> inlinevoidread(T& x){ x = 0; int f = 0, ch = Gc(); while (!isdigit(ch)) f |= ch == '-', ch = Gc(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = Gc(); if (f) x = -x; } } using IO::read;
constint MAXN = 5e5 + 5, MAXM = 114514;
int P, W[MAXN]; int fact[MAXM], tot;
intfpow(int base, int b, int m = P){ int ret = 1; while (b > 0) { if (b & 1) ret = 1LL * ret * base % m; base = 1LL * base * base % m, b >>= 1; } return ret % m; }
namespace Poly { // f(w ^ {an+b}_{pn}) = sum (w ^ {an+b}_{pn}) ^ r f_r (w ^ {b}_{n}) int r[MAXN]; voidRev(int* f, constint& n){ for (int k = tot, Mid = n; k; Mid /= fact[k--]) { // i, l = an, j = b for (int idx = 0, i = 0; i < n; i += Mid) for (int j = 0; j < fact[k]; ++j) for (int l = 0; l < Mid; l += fact[k]) r[idx++] = f[i + j + l]; for (int i = 0; i < n; ++i) f[i] = r[i]; } }
voidNTT(int* f, constint& n, constint& type){ staticint tmp[MAXN]; Rev(f, n); for (int k = 1, Mid = 1; k <= tot; Mid *= fact[k++]) { constint& unit = W[n / (Mid * fact[k])]; memset(tmp, 0, n * sizeof (int)); // i = an, j = b, l = b' for (int i = 0; i < n; i += Mid * fact[k]) { int wk = 1; for (int j = 0; j < Mid * fact[k]; ++j) { for (int w = 1, l = j % Mid; l < Mid * fact[k]; l += Mid) { tmp[i + j] = (tmp[i + j] + 1LL * w * f[i + l] % P) % P; w = 1LL * w * wk % P; } wk = 1LL * wk * unit % P; } } memcpy(f, tmp, n * sizeof (int)); } if (type < 0) { // n * n = 1 (mod n + 1) for (int i = 0; i < n; ++i) f[i] = 1LL * f[i] * n % P; reverse(f + 1, f + n); } } }
intproot(int p){ int phi = p - 1; tot = 0; for (int d = 2; d*d <= phi; ++d) while (phi % d == 0) phi /= d, fact[++tot] = d; if (phi > 1) fact[++tot] = phi; phi = p - 1; for (int g = 2; g < p; ++g) { bool flag = true; for (int i = 1; i <= tot && flag; ++i) if (fpow(g, phi / fact[i], p) == 1) flag = false; if (flag) return g; } return-1; }
int n, C; int A[MAXN], B[MAXN];
inlinevoidPolyPre(){ W[0] = 1, W[1] = proot(P); for (int i = 2; i < n; ++i) W[i] = 1LL * W[1] * W[i-1] % P; }
intmain(){ #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); #endif // input read(n), read(C); for (int i = 0; i < n; ++i) read(A[i]); for (int i = 0; i < n; ++i) read(B[i]); // solve P = n + 1, PolyPre(); Poly::NTT(A, n, 1), Poly::NTT(B, n, 1); for (int i = 0; i < n; ++i) A[i] = 1LL * A[i] * fpow(B[i], C) % P; Poly::NTT(A, n, -1); // output for (int i = 0; i < n; ++i) printf("%d\n", A[i]); return0; }