递归求解即可
#include using namespace std; #define int long long namespace NTT { #define pw(n) (1<>1]>>1)|((i&1)<<(l-1)); } } int fastpow(int a,int b){ int ans=1; for(;b;b>>=1,a=1LL*a*a%mod){ if(b&1)ans=1LL*ans*a%mod; } return ans; } void NTT(int *s,int op){ for(int i=0;i A,vector B,vector &C) { n=A.size()-1; m=B.size()-1; for(int i=0;i<=n;i++) a[i]=A[i]; for(int i=0;i<=m;i++) b[i]=B[i]; m+=n; bitnum=0; for(bit=1;bit<=m;bit<<=1)bitnum++; getrev(bitnum); NTT(a,1); NTT(b,1); for(int i=0;i a; void cut(int n) { while(a.size()>n) a.pop_back(); } poly operator *(int b) { poly c=*this; for(int i=0;i>=1) if(q&1) r*=p, r%=mod; return r; } int inv(int p) { return qpow(p, mod-2); } poly solve(poly A, int n) { A.cut(n); poly B; if(n==1) { B.a.push_back(inv(A.a[0])); } else { poly Bi = solve(A,(n-1)/2+1); B = Bi*2 - A*Bi*Bi; B.cut(n); } return B; } signed main() { ios::sync_with_stdio(false); cin>>n; for(int i=0;i>a[i]; poly A; for(int i=0;i