BTCODE_A - Traversing Grid

no tags 

Given 2 points in 2 dimensional space (xs,ys) and (xd,yd), your task is to find whether (xd,yd) can be reached from (xs,ys) by making a sequence of zero or more operations.
From a given point (x, y), the operations possible are:
a) Move to point (y, x)
b) Move to point (x, -y)
c) Move to point (x+y, y)
d) Move to point (2*x, y)

Input

The first line of input contains T, the number of test cases. T lines follow, one for each test case. For each test case, the input contains one line denoting the 4 integers xs, ys, xd, yd

Output

Output T lines, one for each test case. For each test case, output "YES" if (xd,yd) is reachable from (xs,ys) and "NO" otherwise. (quotes for clarity)

Example

Input:
1
1 1 2 2

Output:
YES

Constraints:
T <= 25
-10^10 <= xs, ys, xd, yd <= 10^10
Note that, although the input values are constrained by the above inequality, the coordinates of the points
at the intermediate steps need not be.

Explanation:

Test case 1: We can move in the following manner: (1,1) -> (2,1), using the operation (x,y) -> (2*x,y). Then, move from (2,1) -> (1,2), using the operation (x,y) -> (y,x). Finally use the operation (x,y) -> (2*x,y) to move from (1,2) -> (2,2).


hide comments
nadstratosfer: 2018-06-07 01:51:48

Taking the usual suspects lightly costed me 40mins of staring at the screen wondering WTF. Good problem, fun to visualize and figure out.

Piyush Kumar: 2016-06-11 15:22:49

Can somebody provide more test cases?

5star: 2014-06-25 21:35:00

Great question :)

Amit Kumar: 2012-09-02 15:20:51

Tricky test cases please...

@suhash tell me why my code (7580002)
is wrong

Ajey Golsangi: 2012-01-13 15:44:39

Good one.


Added by:suhash
Date:2011-02-26
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Bytecode 2011, NIT Trichy, India