forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcd3.cpp
47 lines (47 loc) · 921 Bytes
/
gcd3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 2016-07-01
#include <iostream>
#include <deque>
using namespace std;
typedef deque<int> T;
bool e(const T& n) {
return n.back() % 2 == 0;
}
void s(T& n) {
int c = 0;
for (int i = 0; i < (int)n.size(); i++) {
int d = 10*c + n[i];
c = d%2;
n[i] = d/2;
}
if (n.front() == 0) {
n.pop_front();
}
}
T f(const string& s) {
T r(s.size());
for (int i = 0; i < (int)s.length(); i++) {
r[i] = s[i] - '0';
}
return r;
}
int main() {
ios::sync_with_stdio(false);
int t; cin >> t;
while (t--) {
string P, Q;
int K;
cin >> P >> Q >> K;
T N = f(P), M = f(Q);
if (e(N)) {
int p = 0;
while (p < K && e(N)) {
p++;
s(N);
}
cout << (1 << p) << "\n";
} else {
cout << "1\n";
}
}
return 0;
}