Adam is standing at a point in an infinite 2D grid. He wants to know if he can reach the point or not. The only operation he can do is to move to point from some point . It is given that he can move to any point on this 2D grid, i.e., the points having positive or negative (or ) coordinates.
Tell Adam whether he can reach or not.
Example:
Input: a = 2, b = 1, x = 2, y = 3
Output: YES
Approach
C++
#include <bits/stdc++.h>using namespace std;string solve(long a, long b, long x, long y){if (__gcd(a, b) == __gcd(x, y))return "YES";elsereturn "NO";}int main(){long a = 2, b = 1;long x = 2, y = 3;cout << solve(a, b, x, y) << "\n";return 0;}
No comments:
Post a Comment