fft。
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<complex> #define maxn 300500 #define pi acos(-1) using namespace std; typedef complex<double> E; int n,m,l=0,c[maxn],r[maxn]; E a[maxn],b[maxn]; void fft(E *x,int f) { for (int i=0;i<n;i++) if (i<r[i]) swap(x[i],x[r[i]]); for (int i=1;i<n;i<<=1) { E wn(cos(pi/i),f*sin(pi/i)); for (int j=0;j<n;j+=(i<<1)) { E w(1,0); for (int k=0;k<i;k++) { E r1,r2; r1=x[j+k];r2=w*x[i+j+k]; x[j+k]=r1+r2;x[j+k+i]=r1-r2; w*=wn; } } } if (f==-1) { for (int i=0;i<n;i++) x[i]/=n; } } int main() { scanf("%d",&n);n--; for (int i=0;i<=n;i++) { int x,y; scanf("%d%d",&x,&y); a[i].real()=x;b[n-i].real()=y; } m=2*n; for (n=1;n<=m;n<<=1) l++; for (int i=0;i<n;i++) r[i]=(r[i>>1]>>1)|((i&1)<<(l-1)); fft(a,1);fft(b,1); for (int i=0;i<n;i++) a[i]*=b[i]; fft(a,-1); for(int i=m/2;i<=m;i++) printf("%d ",(int)(a[i].real()+0.1)); return 0; }