BZOJ 2179 FFT快速傅利葉(FFT)

2021-08-07 10:56:27 字數 1689 閱讀 4355

description

給出兩個

n 位

10進製整數

x 和

y,你需要計算x∗

y input

第一行乙個正整數

n 。 第二行描述乙個位數為

n的正整數

x 。 第三行描述乙個位數為

n的正整數

y 。n≤

60000

output

輸出一行,即x∗

y 的結果。

sample input1

3 4sample output

solution

fft模版題

code

#include

#include

#include

#include

using

namespace

std;

#define maxn 65536+5

const

double pi=acos(-1.0);

struct cp

;} cp operator -(const cp &o)const ;}

cp operator *(const cp &o)const ;}

cp operator *(const

double &o)const ;}

cp operator !() const;}

}w[maxn];

int pos[maxn];

void fft_init(int len)

; for(unsigned i=2;i<=len;i<<=1)

;for(int j=i>>1;j>=0;j-=2)w[j]=w[j>>1];

for(int j=1;j>1;j+=2)w[j]=w[j-1]*g;

for(int j=0;j>1);

for(int l=0;l>1;l++)}}

if(sta==-1)for(int i=0;ivoid fft(int *a,int *b,int n,int m,int *c)

)*0.25;

}for(int i=len/2;iint j=len-1&len-i;

z[i]=x[i]*y[i]-(x[i]-!x[j])*(y[i]-!y[j])*((cp)-w[i^len>>1])*0.25;

}fft(z,len,-1);

for(int i=0;iif(i&1)c[i]=(int)(z[i>>1].b+0.5);

else c[i]=(int)(z[i>>1].a+0.5);

}char s1[maxn],s2[maxn];

int n,a[maxn],b[maxn],c[maxn<<1];

int main()

int len=n+n-1;

while(c[len]==0&&len>0)len--;

for(int i=len;i>=0;i--)printf("%c",c[i]+'0');

printf("\n");

}return

0;}

BZOJ2179 FFT快速傅利葉 FFT

給出兩個n位10進製整數x和y,你需要計算x y。第一行乙個正整數n。第二行描述乙個位數為n的正整數x。第三行描述乙個位數為n的正整數y。輸出一行,即x y的結果。13 412資料範圍 n 60000 fft模板題,做的時候注意處理一下進製和前導零就好 1 include2 include3 inc...

BZOJ 2179 FFT快速傅利葉

description 給出兩個n位10進製整數x和y,你需要計算x y。題目分析 fft裸題用來快速計算高精度的乘法,從n 2變成了n。其實不會,隨便抄了乙個模板。以後再慢慢學。include using namespace std const double pi acos 1.0 int rev...

BZOJ2179 FFT快速傅利葉

標籤 fft 題目傳送門 description 給出兩個n位10進製整數x和y,你需要計算x y。input 第一行乙個正整數n。第二行描述乙個位數為n的正整數x。第三行描述乙個位數為n的正整數y。output 輸出一行,即x y的結果。sample input 1sample output 12...