【法法塔】【FFT】【快速傅里叶离散变化】luogu P1919 P3803

迭代实现
// luogu-judger-enable-o2
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
typedef vector vi;
const double pi=acos(-1);
const int MAXN=1e7+11;
#define For(a,b,c) for (ll (a)=(b);(a)<(c);(a)++)
#define foreach(iter,V) for (__typeof((V).begin()) iter=(V).begin();iter!=(V).end();iter++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
struct cp{
    double x,y;
    cp(){}
    cp(double nx,double ny){
        x=nx;y=ny;
    }
    cp operator + (cp &a)	{return cp(a.x+x,a.y+y);}
    cp operator - (cp &a)	{return cp(x-a.x,y-a.y);}
    cp operator * (cp &a)	{return cp(a.x*x-a.y*y,a.x*y+a.y*x);}
}a[MAXN],b[MAXN];
ll limit,l,r[MAXN];
void fast_fast_tle(cp *A,ll type){	
    For(i,0,limit)	if (i>c; 
        a[i].x=c-'0';
    }
    For(i,0,m)	{
    	cin>>c;
        b[i].x=c-'0';
    }
    limit=1;
    while (limit<=m+n)	limit*=2,l++;
    For(i,0,limit)	r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
    fast_fast_tle(a,1);
    fast_fast_tle(b,1);
    For(i,0,limit+1)	a[i]=a[i]*b[i];
    fast_fast_tle(a,-1);
    For(i,0,m+n-1)	ch[i+1]=(int)(a[i].x/limit+0.5);
	int ed=1;
	for (int i=m+n-1;i>=1;i--)
		if (ch[i]>=10){
			ch[i-1]+=ch[i]/10;
			ch[i]%=10;
			if (i==1)	ed=0;
		}
	while(ch[ed]==0&&ed

你可能感兴趣的:(【法法塔】【FFT】【快速傅里叶离散变化】luogu P1919 P3803)