summaryrefslogtreecommitdiff
path: root/math
diff options
context:
space:
mode:
authorNoobie99 <noob999noob999@gmail.com>2024-01-30 22:01:40 +0100
committerNoobie99 <noob999noob999@gmail.com>2024-01-30 22:01:40 +0100
commit9819b394e494bdfaaf55893a3f90b71ddb52227e (patch)
tree32ecef8105ccaaff1f53a046baaea373d60987a1 /math
parent44cf3a27b1d12445029024e6d9258268de39e584 (diff)
add multiply function for fft
Diffstat (limited to 'math')
-rw-r--r--math/transforms/multiply.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/math/transforms/multiply.cpp b/math/transforms/multiply.cpp
new file mode 100644
index 0000000..59c394e
--- /dev/null
+++ b/math/transforms/multiply.cpp
@@ -0,0 +1,12 @@
+vector<ll> mul(vector<ll>& a, vector<ll>& b) {
+ int n = 1 << (__lg(sz(a) + sz(b)) + 1);
+ vector<cplx> a2(all(a)), b2(all(b));
+ a2.resize(n), b2.resize(n);
+ fft(a2), fft(b2);
+ for (int i=0; i<n; i++) a2[i] *= b2[i];
+ fft(a2, true);
+
+ vector<ll> ans(n);
+ for (int i=0; i<n; i++) ans[i] = llround(a2[i].real());
+ return ans;
+}