I tried to solve this question asked at atcoder but didn’t succeed, please help me how to solve questions like this

problem link:-

**Code**:

```
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
if(y%2 == 0)
{
if(y >= 2*x && y <= 4*x) cout << "Yes\n";
else cout << "No\n";
}
else cout << "No\n";
return 0;
}
```

**Explanation**:

It is a problem of linear equations in two variables. Let the number of cranes be A and the number of turtles be B, then A+B = X and 2A+4B = Y. On solving these we get A = 2X-(Y/2) and B = (Y/2)-X. Since A and B must be non-negative integers we get the conditions as **2 divides Y** and **2X<=Y<=4X**.

1 Like

thanks very much