forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
40 lines (33 loc) · 616 Bytes
/
C.cpp
File metadata and controls
40 lines (33 loc) · 616 Bytes
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
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
if (x < y) return gcd(y, x);
if (x % y == 0) return y;
return gcd(y, x % y);
}
int main() {
long long x, y, q;
cin >> x >> y;
if (gcd(x, y) != 1) {
cout << "Impossible" << endl;
} else {
while (x > 1 && y > 1) {
if (x > y) {
q = x / y;
x = x % y;
cout << q << "A";
} else {
q = y / x;
y = y % x;
cout << q << "B";
}
}
if (x > 1) {
cout << (x - 1) << "A";
}
if (y > 1) {
cout << (y - 1) << "B";
}
cout << endl;
}
}