luogu#P5205. 【模板】多项式开根

    ID: 4162 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>快速傅里叶变换 FFT快速数论变换 NTT

【模板】多项式开根

Background

This is a template problem, with no background.

Problem Description

Given a polynomial A(x)A(x) of degree n1n - 1, find a polynomial B(x)B(x) modulo xnx^n such that B2(x)A(x)(modxn)B^2(x) \equiv A(x) \pmod{x^n}. If there are multiple solutions, output the one with the smaller constant-term coefficient.

All polynomial coefficients are computed modulo 998244353998244353.

Input Format

The first line contains a positive integer nn.

The next line contains nn integers, representing the coefficients a0,a1,,an1a_0, a_1, \dots, a_{n-1} of the polynomial in order.

It is guaranteed that a0=1a_0 = 1.

Output Format

Output nn integers, representing the coefficients b0,b1,,bn1b_0, b_1, \dots, b_{n-1} of the answer polynomial.

3
1 2 1

1 1 0

7
1 8596489 489489 4894 1564 489 35789489  

1 503420421 924499237 13354513 217017417 707895465 411020414

Hint

For 100%100\% of the testdata: 1n1051 \le n \le 10^5, 0ai<9982443530 \le a_i < 998244353.

Translated by ChatGPT 5