Skip to content

Commit

Permalink
add GCD3
Browse files Browse the repository at this point in the history
  • Loading branch information
t3nsor committed Jul 2, 2016
1 parent 27456fd commit d99a877
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions gcd3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}

0 comments on commit d99a877

Please sign in to comment.