#P5373. Polynomial Composition Modulo Truncation

    ID: 18606 Type: Default 1000ms 256MiB

Polynomial Composition Modulo Truncation

Polynomial Composition Modulo Truncation

Given a polynomial \(F(x)\) of degree \(n\) and a polynomial \(G(x)\) of degree \(m\), compute a polynomial \(H(x)\) of degree \(n\) such that

\[ H(x) \equiv F(G(x)) \; (\bmod\; x^{n+1}), \]

In other words, if \[ F(x) = \sum_{i=0}^{n} f_i x^i, \quad \text{then} \]

\[ H(x) \equiv \sum_{i=0}^{n} f_i \cdot (G(x))^i \; (\bmod\; x^{n+1}). \]

Output each coefficient of \(H(x)\) modulo 998244353.

inputFormat

The first line contains two integers \(n\) and \(m\) where \(n\) is the degree of polynomial \(F(x)\) and \(m\) is the degree of polynomial \(G(x)\).

The second line contains \(n+1\) integers: \(f_0, f_1, \dots, f_n\), the coefficients of \(F(x)\) in increasing order of degree.

The third line contains \(m+1\) integers: \(g_0, g_1, \dots, g_m\), the coefficients of \(G(x)\) in increasing order of degree.

outputFormat

Output \(n+1\) space‐separated integers which are the coefficients of the polynomial \(H(x)\) in increasing order of degree, each taken modulo 998244353.

sample

2 1
1 2 3
1 1
6 8 3