-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path(introductory) Coin Piles
More file actions
40 lines (39 loc) · 913 Bytes
/
Copy path(introductory) Coin Piles
File metadata and controls
40 lines (39 loc) · 913 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 <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--){
int x, y;
cin >> x >> y;
// Keep making moves until both piles are empty or no more moves can be made
while (x > 0 && y > 0) {
if (x > y) {
int diff=x-y;
x -= 2*(diff);
y -= 1*(diff);
}
else if (y > x) {
int diff=y-x;
x -= 1*(diff);
y -= 2*(diff);
}
else {
if(x%3==0){
x=0;
y=0;
}else{
break;
}
}
}
if (x == 0 && y == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}