time limit: 10 sec
memory limit: 259 mb
submit: 2803
solved: 1431 [
submit][
status][
discuss]
給出兩個n位10進製整數x和y,你需要計算x*y。
第一行乙個正整數n。 第二行描述乙個位數為n的正整數x。 第三行描述乙個位數為n的正整數y。
輸出一行,即x*y的結果。13
412資料範圍:
n<=60000 [
submit][
status][
discuss]
上乙個快速數論變換,在fft基礎上稍作修改就行
模數取1004535809,原根是3
#include#include#include#include#includeusing namespace std;
const int maxn = 2e5 + 10;
typedef long long ll;
const ll mo = 1004535809;
ll g[maxn],a[maxn],b[maxn],c[maxn],d[maxn];
int n,n,l,rev[maxn],num[maxn];
char ch[maxn];
ll ksm(ll x,ll y)
return ret;}
void ntt(ll *a,int on)
} if (on == -1) }
int main()
scanf("%s",ch);
for (int i = 0; i < n; i++)
a[i] = ch[n - i - 1] - '0';
scanf("%s",ch);
for (int i = 0; i < n; i++)
b[i] = ch[n - i - 1] - '0';
g[0] = g[n] = 1;
g[1] = ksm(3,(mo - 1)/(1ll*n));
for (int i = 2; i < n; i++)
g[i] = g[i-1]*g[1]%mo;
ntt(a,1); ntt(b,1);
for (int i = 0; i < n; i++)
c[i] = a[i]*b[i]%mo;
for (int i = 0; i < n/2; i++)
swap(g[i],g[n - i]);
ntt(c,-1);
for (int i = 0; i < n; i++)
int pos;
for (int i = n - 1; i >= 0; i--)
if (c[i])
for (int i = pos; i >= 0; i--)
printf("%d",c[i]);
return 0;
}
BZOJ 2179 FFT快速傅利葉(FFT)
description 給出兩個 n 位 10進製整數 x 和 y,你需要計算x y input 第一行乙個正整數 n 第二行描述乙個位數為 n的正整數 x 第三行描述乙個位數為 n的正整數 y n 60000 output 輸出一行,即x y 的結果。sample input1 3 4sample...
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...