#P4245. 【模板】任意模数多项式乘法

    ID: 3174 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学O2优化素数判断,质数,筛法中国剩余定理,CRT快速傅里叶变换 FFT

【模板】任意模数多项式乘法

Description

Given 22 polynomials F(x),G(x)F(x), G(x), compute F(x)G(x)F(x) * G(x). The coefficients are taken modulo pp, and it is not guaranteed that pp can be written in the form p=a2k+1p = a \cdot 2^k + 1.

Input Format

The input consists of 33 lines.
The first line contains 33 integers n,m,pn, m, p, representing the degrees of F(x)F(x) and G(x)G(x), and the modulus pp.
The second line contains n+1n+1 integers; the ii-th integer aia_i denotes the coefficient of the (i1)(i-1)-th term of F(x)F(x).
The third line contains m+1m+1 integers; the ii-th integer bib_i denotes the coefficient of the (i1)(i-1)-th term of G(x)G(x).

Output Format

Output n+m+1n+m+1 integers. The ii-th integer cic_i denotes the coefficient of the (i1)(i-1)-th term of F(x)G(x)F(x) * G(x).

5 8 28
19 32 0 182 99 95
77 54 15 3 98 66 21 20 38
7 18 25 19 5 13 12 2 9 22 5 27 6 26

Hint

For 100%100\% of the testdata, 1n,m1051 \leq n, m \leq 10^5, 0ai,bi1090 \leq a_i, b_i \leq 10^9, 2p109+92 \leq p \leq 10^9 + 9.

Translated by ChatGPT 5