# 【洛谷4238】【模板】多项式乘法逆

### 推式子

$F(x)*H(x)\equiv1(mod\ x^{\lfloor\frac n2\rfloor})$

$F(x)*G(x)\equiv1(mod\ x^{\lfloor\frac n2\rfloor})$

$F(x)*(G(x)-H(x))\equiv0(mod\ x^{\lfloor\frac n2\rfloor})$

$F(x)$去掉，就得到：

$G(x)-H(x)\equiv0(mod\ x^{\lfloor\frac n2\rfloor})$

$(G(x)-H(x))^2\equiv0(mod\ x^n)$

$G(x)^2-2G(x)*H(x)+H(x)^2\equiv0(mod\ x^n)$

$F(x)*G(x)^2-2F(x)*G(x)*H(x)+F(x)*H(x)^2\equiv0(mod\ x^n)$

$G(x)-2H(x)+F(x)*H(x)^2\equiv0(mod\ x^n)$

$G(x)\equiv2H(x)-F(x)*H(x)^2(mod\ x^n)$

### 代码

#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100000
#define X 998244353
#define Qinv(x) Qpow(x,X-2)
#define swap(x,y) (x^=y^=x^=y)
using namespace std;
int n,a[N+5],b[4*N+5];
class FastIO
{
private:
#define FS 100000
#define pc(c) (C==E&&(clear(),0),*C++=c)
#define tn (x<<3)+(x<<1)
#define D isdigit(c=tc())
int T;char c,*A,*B,*C,*E,FI[FS],FO[FS],S[FS];
public:
I FastIO() {A=B=FI,C=FO,E=FO+FS;}
Tp I void read(Ty& x) {x=0;W(!D);W(x=tn+(c&15),D);}
Tp I void write(Ty x) {W(S[++T]=x%10+48,x/=10);W(T) pc(S[T--]);}
Tp I void write(Con Ty& x,Con char& y) {write(x),pc(y);}
I void clear() {fwrite(FO,1,C-FO,stdout),C=FO;}
}F;
I int Qpow(RI x,RI y) {RI t=1;W(y) y&1&&(t=1LL*t*x%X),x=1LL*x*x%X,y>>=1;return t;}
template<int SZ,int PR> class Poly
{
private:
int IPR,P,L,R[4*N+5],t[4*N+5];
I void T(int *s,CI op)
{
RI i,j,k,U,S,x,y;for(i=0;i^P;++i) i<R[i]&&swap(s[i],s[R[i]]);
for(i=1;i^P;i<<=1) for(U=Qpow(~op?PR:IPR,(X-1)/(i<<1)),j=0;j^P;j+=i<<1)
for(S=1,k=0;k^i;++k,S=1LL*S*U%X) s[j+k]=((x=s[j+k])+(y=1LL*S*s[i+j+k]%X))%X,s[i+j+k]=(x-y+X)%X;
}
public:
I Poly() {IPR=Qinv(PR);}
I void Inv(CI n,int *a,int *b)
{
if(!n) return (void)(b[0]=Qinv(a[0]));Inv(n>>1,a,b);//处理边界，不在边界则继续递归
RI i;P=1,L=0;W(P<=(n<<1)) P<<=1,++L;for(i=0;i^P;++i) R[i]=(R[i>>1]>>1)|((i&1)<<L-1);//预处理
for(i=0;i<=n;++i) t[i]=a[i];T(b,1),T(t,1);//NTT
for(i=0;i^P;++i) b[i]=(2LL*b[i]%X-1LL*t[i]*b[i]%X*b[i]%X+X)%X;T(b,-1);//计算新多项式
RI t=Qinv(P);for(i=0;i<=n;++i) b[i]=1LL*b[i]*t%X;for(i=n+1;i^P;++i) b[i]=0;//注意将高位清空，否则会影响后续操作
}
};Poly<N,3> P;
int main()
{