#P5373. 【模板】多项式复合函数

    ID: 6107 远端评测题 4000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学O2优化快速傅里叶变换 FFT快速数论变换 NTT

【模板】多项式复合函数

Background

One day, NaCly_Fish saw rqy\mathsf r \color{red} \mathsf{qy} say in the group chat: “I finally finished writing polynomial composition! qwq”.
So she curiously asked rqy\mathsf r \color{red} \mathsf{qy}: “How do you write this thing?”.

rqy\mathsf r \color{red} \mathsf{qy} only threw her a PDF in “Yingwen” (pinyin), but she could not understand it at all.
So she asked you for help, hoping you can help her solve this difficult problem.

Problem Description

Given an nn-degree polynomial F(x)F(x) and an mm-degree polynomial G(x)G(x), you need to find an nn-degree polynomial H(x)H(x) that satisfies:

H(x)F(G(x)) (mod xn+1)H(x) \equiv F(G(x))\space (\text{mod }x^{n+1})

In other words, the polynomial you need should satisfy:

$$H(x) \equiv \sum\limits_{i=0}^n [x^i]F(x)\times G(x)^i \space (\text{mod }x^{n+1})$$

Take all coefficients of the result modulo 998244353998244353.

Input Format

The first line contains two positive integers n,mn,m, representing the degrees of F(x)F(x) and G(x)G(x).
The second line contains n+1n+1 non-negative integers fif_i, representing the coefficient of the xix^i term of F(x)F(x).
The third line contains m+1m+1 non-negative integers gig_i, representing the coefficient of the xix^i term of G(x)G(x).

Output Format

Output one line with n+1n+1 non-negative integers, from low degree to high degree, representing the coefficients of H(x)H(x).

5 1
1 9 2 6 0 8
1 7

26 497 4900 29498 96040 134456 

Hint

Constraints:
1mn200001\le m \le n \le 20000
fi,gi[0,998244353)Zf_i,g_i \in [0,998244353)\cap \mathbb Z

Translated by ChatGPT 5