(color{#0066ff}{ 题目描述 })
给定一个多项式(F(x)) ,请求出一个多项式 (G(x)), 满足 (F(x) * G(x) equiv 1 ( mathrm{mod:} x^n )),系数对 (998244353) 取模。
(color{#0066ff}{输入格式})
首先输入一个整数 (n) 表示输入多项式的次数。 接着输入 (n) 个整数,第 (i) 个整数 (a_i) 代表 (F(x)) 次数为 (i-1) 的项的系数。
(color{#0066ff}{输出格式})
输出 (n) 个数字,第 (i) 个整数 (b_i) 代表 (G(x)) 次数为 (i-1) 的项的系数。
(color{#0066ff}{输入样例})
5
1 6 3 4 9
(color{#0066ff}{输出样例})
1 998244347 33 998244169 1020
(color{#0066ff}{数据范围与提示})
(1leq n leq 10^5,0le aile 10^9)
(color{#0066ff}{ 题解 })
牛顿迭代推一波
给出(A(x)),求(B(x)),使(A(x) equiv B(x) ( mathrm{mod:} x^n ))
设(F(x)=B(x))
设(G(F(x))= frac{1}{A(x)*F(x)}-1equiv 0( mathrm{mod:} x^n ))
则(G'(F(x))=-frac{1}{A(x)*F^2(x)})
根据牛顿迭代,有(F(x)equiv F_0(x)-frac{G(F_0(x))}{G'(F_0(x))} ( mathrm{mod:} x^n ))
于是 (F(x)equiv F_0(x)-frac{frac{1}{A(x)F_0(x)}-1}{-frac{1}{A(x)F_0^2(x)}} ( mathrm{mod:} x^n )equiv 2*F_0(x)-A(x)*F_0^2(x) ( mathrm{mod:} x^n ))
每次长度二分,递归求(F_0)即可
#include<bits/stdc++.h>
#define LL long long
LL in() {
char ch; LL x = 0, f = 1;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
return x * f;
}
using std::vector;
const int mod = 998244353;
const int maxn = 4e5 + 10;
int r[maxn], len;
LL ksm(LL x, LL y) {
LL re = 1LL;
while(y) {
if(y & 1) re = re * x % mod;
x = x * x % mod;
y >>= 1;
}
return re;
}
void FNTT(vector<int> &A, int flag) {
A.resize(len);
for(int i = 0; i < len; i++) if(i < r[i]) std::swap(A[i], A[r[i]]);
for(int l = 1; l < len; l <<= 1) {
int w0 = ksm(3, (mod - 1) / (l << 1));
for(int i = 0; i < len; i += (l << 1)) {
int w = 1, a0 = i, a1 = i + l;
for(int k = 0; k < l; k++, a0++, a1++, w = 1LL * w * w0 % mod) {
int tmp = 1LL * A[a1] * w % mod;
A[a1] = ((A[a0] - tmp) % mod + mod) % mod;
A[a0] = (A[a0] + tmp) % mod;
}
}
}
if(flag == -1) {
std::reverse(A.begin() + 1, A.end());
int inv = ksm(len, mod - 2);
for(int i = 0; i < len; i++) A[i] = 1LL * A[i] * inv % mod;
}
}
vector<int> operator * (const vector<int> &A, const vector<int> &B) {
int tot = A.size() + B.size() - 1;
vector<int> C = A, D = B;
for(len = 1; len <= tot; len <<= 1);
for(int i = 0; i < len; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) * (len >> 1));
FNTT(C, 1), FNTT(D, 1);
vector<int> ans;
ans.resize(len);
for(int i = 0; i < len; i++) ans[i] = 1LL * C[i] * D[i] % mod;
FNTT(ans, -1);
ans.resize(tot);
return ans;
}
vector<int> operator - (const vector<int> &A, const vector<int> &B) {
vector<int> ans;
for(int i = 0; i < (int)std::min(A.size(), B.size()); i++) ans.push_back(A[i] - B[i]);
if(A.size() < B.size()) for(int i = A.size(); i < (int)B.size(); i++) ans.push_back(-B[i]);
if(A.size() > B.size()) for(int i = B.size(); i < (int)A.size(); i++) ans.push_back(A[i]);
return ans;
}
vector<int> inv(const vector<int> &A) {
if(A.size() == 1) {
vector<int> ans;
ans.push_back(ksm(A[0], mod - 2));
return ans;
}
int n = A.size(), _ = (n + 1) >> 1;
vector<int> ans, B = A;
ans.push_back(2);
B.resize(_);
B = inv(B);
ans = B * (ans - A * B);
ans.resize(n);
return ans;
}
int main() {
int n = in();
vector<int> a;
for(int i = 0; i < n; i++) a.push_back(in());
a = inv(a);
for(int i = 0; i < n; i++) printf("%d%c", a[i], i == n - 1? '
' : ' ');
return 0;
}