Skip to content

Commit e2b1f60

Browse files
authored
Merge pull request #16 from IMEplusplus/tests/fft
Add fft test
2 parents de58519 + cf05aad commit e2b1f60

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/math/fft.test.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// @problem_url: https://www.spoj.com/problems/MUL/
2+
#include<bits/stdc++.h>
3+
4+
using namespace std;
5+
typedef long double ld;
6+
const ld PI = acos(-1);
7+
8+
const int N = 2e5;
9+
10+
// @include: math/fft.cpp
11+
12+
int main() {
13+
int n;
14+
cin >> n;
15+
16+
while (n--) {
17+
string a, b;
18+
cin >> a >> b;
19+
20+
int size = a.size() + b.size();
21+
while (size - (size & -size) != 0) size -= size & -size;
22+
size *= 2;
23+
24+
vector<T> va(size);
25+
vector<T> vb(size);
26+
27+
for (int i = 0; i < a.size(); i++) va[a.size() - i - 1].x = a[i] - '0';
28+
for (int i = 0; i < b.size(); i++) vb[b.size() - i - 1].x = b[i] - '0';
29+
30+
multiply(&va[0], &vb[0], size);
31+
32+
string answer;
33+
int goes = 0;
34+
35+
for (auto c : va) {
36+
int x = c.x + 0.5 + goes;
37+
38+
goes = 0;
39+
if (x > 9) {
40+
goes = x / 10;
41+
x = x % 10;
42+
}
43+
44+
answer.push_back(x + '0');
45+
}
46+
answer.push_back(goes + '0');
47+
48+
while (answer.back() == '0') answer.pop_back();
49+
if (answer.empty()) answer.push_back('0');
50+
reverse(answer.begin(), answer.end());
51+
52+
cout << answer << endl;
53+
}
54+
}

0 commit comments

Comments
 (0)