//#define NDEBUG #include #include #include #include #include namespace n91 { using i8 = std::int_fast8_t; using i32 = std::int_fast32_t; using i64 = std::int_fast64_t; using u8 = std::uint_fast8_t; using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t; using isize = std::ptrdiff_t; using usize = std::size_t; struct rep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr rep(const usize f, const usize l) noexcept : f(std::min(f, l)), l(l) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; struct revrep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr revrep(const usize f, const usize l) noexcept : f(l - 1), l(std::min(f, l) - 1) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; template auto md_vec(const usize n, const T &value) { return std::vector(n, value); } template auto md_vec(const usize n, Args... args) { return std::vector(n, md_vec(args...)); } template constexpr T difference(const T &a, const T &b) noexcept { return a < b ? b - a : a - b; } template void chmin(T &a, const T &b) noexcept { if (b < a) a = b; } template void chmax(T &a, const T &b) noexcept { if (a < b) a = b; } template T scan() { T ret; std::cin >> ret; return ret; } } // namespace n91 #include #include #include #include #include namespace n91 { using usize = std::size_t; using u64 = std::uint_fast64_t; static constexpr u64 Modulus = 998244353; static constexpr u64 PrimitiveRoot = 3; void ntt(std::vector &a) { const usize size = a.size(); const usize m = size - 1; std::vector b(size); u64 root = 1; { u64 base = PrimitiveRoot; u64 exp = (Modulus - 1) / size; while (exp != 0) { if (exp % 2 != 0) { root = root * base % Modulus; } exp /= 2; base = base * base % Modulus; } } for (usize i = size; (i /= 2) != 0;) { std::swap(a, b); u64 c = 1; u64 d = root; for (usize j = 1; j != i; j *= 2) { d = d * d % Modulus; } for (usize j = 0; j != size; j += i) { const usize l = j * 2 & m, r = l + i; for (usize k = 0; k != i; ++k) { a[j + k] = (b[l + k] + b[r + k] * c) % Modulus; } c = c * d % Modulus; } } } void inv_ntt(std::vector &a) { ntt(a); std::reverse(a.begin() + 1, a.end()); const u64 inv = Modulus - (Modulus - 1) / a.size(); for (auto &e : a) { e = e * inv % Modulus; } } } // namespace n91 #include #include #include #include #include namespace n91 { u64 find_primroot(const u64 p) { std::vector factor; { u64 q = p - 1; for (u64 i = 2; i * i <= q; i += 1) { if (q % i == 0) { factor.push_back(i); do { q /= i; } while (q % i == 0); } } if (q != 1) { factor.push_back(q); } } for (u64 &e : factor) { e = (p - 1) / e; } std::mt19937_64 rnd(std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()) .count()); while (true) { const u64 cand = rnd() % (p - 1) + 1; if (std::none_of(factor.cbegin(), factor.cend(), [&](u64 exp) { u64 base = cand; u64 a = 1; while (exp != 0) { if (exp % 2 == 1) { a = a * base % p; } base = base * base % p; exp /= 2; } return a == 1; })) { return cand; } } } void main_() { //* std::ios::sync_with_stdio(false); std::cin.tie(nullptr); //*/ const u64 p = scan(); const auto is_pr = [&](const u64 a) { u64 t = 1; for (const usize i : rep(0, p - 2)) { t = t * a % p; if (t == 1) { return false; } } return true; }; const u64 proot = find_primroot(p); std::vector A(p), B(p); for (const usize i : rep(1, p)) { std::cin >> A[i]; } for (const usize i : rep(1, p)) { std::cin >> B[i]; } const usize s = [&]() { usize s = 1; while (s < p - 1) { s *= 2; } return s * 2; }(); std::vector a(s), b(s); { u64 t = 1; for (const usize i : rep(0, p - 1)) { a[i] = A[t]; b[i] = B[t]; t = t * proot % p; } } ntt(a); ntt(b); std::vector c(s); for (const usize i : rep(0, s)) { c[i] = a[i] * b[i] % Modulus; } inv_ntt(c); for (const usize i : rep(p - 1, s)) { c[i % (p - 1)] = (c[i % (p - 1)] + c[i]) % Modulus; } std::vector C(p); { u64 t = 1; for (const usize i : rep(0, p - 1)) { C[t] = c[i]; t = t * proot % p; } } for (const usize i : rep(1, p)) { std::cout << C[i] << (i != p - 1 ? ' ' : '\n'); } } } // namespace n91 int main() { n91::main_(); return 0; }