#P4512. 【模板】多项式除法

【模板】多项式除法

Description

Given an nn-degree polynomial F(x)F(x) and an mm-degree polynomial G(x)G(x), find polynomials Q(x)Q(x) and R(x)R(x) such that:

  • degQ(x)=nm\deg Q(x) = n - m, and degR(x)<m\deg R(x) < m.
  • F(x)=Q(x)G(x)+R(x)F(x) = Q(x) * G(x) + R(x).

All operations are performed modulo 998244353998244353.

Input Format

The first line contains two integers nn and mm, as described above.
The second line contains n+1n+1 integers, giving the coefficients of F(x)F(x) from low to high degree.
The third line contains m+1m+1 integers, giving the coefficients of G(x)G(x) from low to high degree.

Output Format

The first line contains nm+1n - m + 1 integers, giving the coefficients of Q(x)Q(x) from low to high degree.
The second line contains mm integers, giving the coefficients of R(x)R(x) from low to high degree.
If degR(x)<m1\deg R(x) < m - 1, pad the remaining coefficients with 00.

5 1
1 9 2 6 0 8
1 7
237340659 335104102 649004347 448191342 855638018
760903695

Hint

For all testdata, 1m<n1051 \le m < n \le 10^5, and the given coefficients belong to [0,998244353)Z[0, 998244353) \cap \mathbb{Z}.

Translated by ChatGPT 5