#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define N (5000000+100)
using namespace std;
double pi=acos(-1.0);
int n,m,fn,l,r[N];
struct complex
{
double x,y;
complex (double xx=0,double yy=0)
{
x=xx; y=yy;
}
}a[N],b[N];
complex operator + (complex a,complex b){return complex(a.x+b.x,a.y+b.y);}
complex operator - (complex a,complex b){return complex(a.x-b.x,a.y-b.y);}
complex operator * (complex a,complex b){return complex(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);}
complex operator / (complex a,double b){return complex(a.x/b,a.y/b);}
void FFT(int n,complex *a,int opt)
{
for (int i=0; i<n; ++i)
if (i<r[i])
swap(a[i],a[r[i]]);
for (int k=1; k<n; k<<=1)
{
complex wn=complex(cos(pi/k),opt*sin(pi/k));
for (int i=0; i<n; i+=(k<<1))
{
complex w=complex(1,0);
for (int j=0; j<k; ++j,w=w*wn)
{
complex x=a[i+j], y=w*a[i+j+k];
a[i+j]=x+y; a[i+j+k]=x-y;
}
}
}
if (opt==-1) for (int i=0; i<n; ++i) a[i]=a[i]/n;
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=0; i<=n; ++i)
scanf("%lf",&a[i].x);
for (int i=0; i<=m; ++i)
scanf("%lf",&b[i].x);
fn=1;
while (fn<=n+m) fn<<=1, l++;
for (int i=0; i<fn; ++i)
r[i]=(r[i>>1]>>1) | ((i&1)<<(l-1));
FFT(fn,a,1); FFT(fn,b,1);
for (int i=0; i<=fn; ++i)
a[i]=a[i]*b[i];
FFT(fn,a,-1);
for (int i=0; i<=n+m; ++i)
printf("%d ",(int)(a[i].x+0.5));
}
| Compilation | N/A | N/A | Compile Error | Score: N/A | 显示更多 |