File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments