【模板】多项式乘法(FFT)

2019-04-13 16:52发布

传送门:https://www.luogu.org/problemnew/show/P3803 #include #define N 2621450 #define pi acos(-1) using namespace std; typedef complex E; int n,m,l,r[N]; E a[N],b[N]; void FFT(E *a,int f){ for(int i=0;i'9'); do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9'); return f*x; } int main(){ n=read();m=read(); for(int i=0;i<=n;i++)a[i]=read(); for(int i=0;i<=m;i++)b[i]=read(); m+=n;for(n=1;n<=m;n<<=1)l++; for(int i=0;i>1]>>1)|((i&1)<<(l-1)); FFT(a,1);FFT(b,1); for(int i=0;i<=n;i++)a[i]=a[i]*b[i]; FFT(a,-1); for(int i=0;i<=m;i++)printf("%d ",(int)(a[i].real()/n+0.5)); }