A*B problem(FFT)
设两个多项式\(A(x)\)和\(B(x)\),它们的系数镜像反转一下,得到的多项式是\(A'(x)\)和\(B'(x)\)。那么\(C(x)=A(x)*B(x)\)和\(C'(x)=A'(x)*B'(x)\)的系数也是镜像反转的。这个,,感性理解一下吧。
于是倒过来搞会很方便。由于是大整数乘法,算完从个位到最高位进一下位就行了。注意数组要开四倍!
#include
#include
#include
using namespace std;
const int maxn=6e4+5;
const double pi=3.1415926535898;
struct Cpx{
double x, y;
Cpx (double t1=0, double t2=0){ x=t1, y=t2; }
}A[maxn*4], B[maxn*4], C[maxn*4];
Cpx operator +(Cpx &a, Cpx &b){ return Cpx(a.x+b.x, a.y+b.y); }
Cpx operator -(Cpx &a, Cpx &b){ return Cpx(a.x-b.x, a.y-b.y); }
Cpx operator *(Cpx &a, Cpx &b){ return Cpx(a.x*b.x-a.y*b.y, a.x*b.y+a.y*b.x); }
void swap(Cpx &x, Cpx &y){ Cpx t=x; x=y; y=t; }
int n, r[maxn*4], limit=1, l, ans[maxn*4]; //这里也要乘4!
void fdft(Cpx *a, int n, int flag){
for (int i=0; i>1]>>1)+((i&1)<<(l-1)); //1<=0; --i){
if (ans[i]>0) flag=true;
if (flag) printf("%d", ans[i]);
}
return 0;
}