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

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

懒得写了,推荐2篇好博客,比较清晰易懂。
FFT
FFT

FFT题集

\(\color{blue}{Code}\)

#include
using namespace std;
const int N=3000006;
const double pi=acos(-1.0);
struct cp {
    double x,y;
    cp (double xx=0,double yy=0) {
        x=xx,y=yy;
    }
} a[N],b[N];
cp operator + (const cp &a,const cp &b) {
    return cp(a.x+b.x,a.y+b.y);
}
cp operator - (const cp &a,const cp &b) {
    return cp(a.x-b.x,a.y-b.y);
}
cp operator * (const cp &a,const cp &b) {
    return cp(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);
}
int n,m,lim=1,l,rev[N];
void fft(cp *a,int o) {
    for(int i=0; i>1]>>1)|((i&1)<<(l-1));
    fft(a,1);
    fft(b,1);
    for(int i=0; i

你可能感兴趣的:(P3803 【模板】多项式乘法(FFT))