#P5277. 【模板】多项式开根(加强版)

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

【模板】多项式开根(加强版)

Background

This is a template problem, with no background.

Problem Description

Given an (n1)(n - 1)-degree polynomial A(x)A(x), 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}.

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,\ldots ,a_{n-1} in order.

It is not guaranteed that a0=1a_0=1, but it is guaranteed that a0a_0 is a quadratic residue modulo 998244353998244353.

Output Format

Output nn non-negative integers, representing the coefficients b0,b1,,bn1b_0,b_1,\ldots ,b_{n-1} of the answer polynomial. If there are multiple solutions, output the one with the smallest lexicographical order of the coefficient sequence (not the character sequence).

3
1 2 1

1 1 0
7
1 8596489 489489 4894 1564 489 35789489  

1 503420421 924499237 13354513 217017417 707895465 411020414

Hint

For 25%25\% of the testdata, n1000n \leq 1000.

For 50%50\% of the testdata, n104n \leq 10^4.

For 75%75\% of the testdata, n5×104n \leq 5\times 10^4.

For 100%100\% of the testdata, n105n \leq 10^5, and ai[0,998244352]Za_i \in [0,998244352] \cap \mathbb{Z}.

Translated by ChatGPT 5