From e16125495bf7507d682df7ec55617a1438ad3746 Mon Sep 17 00:00:00 2001 From: SaiSatwik Date: Fri, 19 Oct 2018 00:11:13 +0530 Subject: [PATCH] Added Polynomial Multiplication using ftt in nlogn complexity cpp code --- PolyMULftt.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 PolyMULftt.cpp diff --git a/PolyMULftt.cpp b/PolyMULftt.cpp new file mode 100644 index 0000000..0fc82b6 --- /dev/null +++ b/PolyMULftt.cpp @@ -0,0 +1,78 @@ +#include +#define ll long long +#define mp make_pair +#define pb push_back +#define ff first +#define ss second +#define MOD 1000000007 +#define endl '\n' +#define M_PI 3.14159265358979323846264338327950288 +using namespace std; +typedef complex cp; +#define MAXN 32768 +void fft(vector &a,vector&b, cp w) +{ + int n=a.size(); + b.resize(n); + if(n==1) + b[0]=a[0]; + else + { + vector b1(n/2),b2(n/2); + for(int i=0;i y1,y2; + fft(b1,y1,w*w); + fft(b2,y2,w*w); + cp wn=cp(1,0); + for(int i=0;i>t; + while(t--) + { + int n; + cin>>n; + vector p1(MAXN,cp(0,0)),p2(MAXN,cp(0,0)),p3,p4,v; + for(int i=0;i<=n;++i) + { + int x; + cin>>x; + p1[i]+=cp(x,0); + } + for(int i=0;i<=n;++i) + { + int x; + cin>>x; + p2[i]+=cp(x,0); + } + double alpha=(double) 2*M_PI/(double) MAXN; + cp w=cp(cos(alpha),sin(alpha)); + fft(p1,p3,w); + fft(p2,p4,w); + for(int i=0;i