Very Quick Rabbits
Practice
3 (4 votes)
C++
Gcd
Math
Number theory
Problem
86% Success 685 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

Alice has a rectangular matrix of size 10^18 x 10^18. We assume that the matrix rows are numbered from 1 to 10^18 from top to bottom, and the matrix columns are numbered from 1 to 10^18 from left to right. Then the cell of the field at the intersection of the x-th row and the y-th column has coordinates (x.y).

Once Alice had tortoises in this matrix, but now he gets bored from tortoises because they are very slow and this large matrix is definitely not for them. So he decides to replace it with rabbits. Initially, rabbits stand at cell (1, 1). One of the hallmarks of rabbits is that they are very fast. They are twice faster than tortoises and can get from a cell (x, y) into a cell (2 ∗ x, y) or (x, 2 ∗ y) in a few seconds. Also they can go to (x, y − x) or (x − y, y). But the rabbits can not go out of the bounds of the matrix.

It turns out that rabbits got hungry very quickly (this is due to a very fast digestive system). So Alice buys food for them for the next q days and puts this food to cell (xi , yi) in the i-th day. But he does not know are these cells reachable. And he asks you to help him. For each day determine can Alice's rabbits be happy or not.

Input format:

  • The first line contains single integer q (1 ≤ q ≤ 3 ∗ 10^5 ) - number of days.
  • The next q lines contains two space-separated integers xi and yi (1 ≤ xi , yi ≤ 10^18) - the coordinates of food.

Output format:

  • Output For each of q days print on a single line "Yes if there is a way from cell (1; 1) to cell (xi , yi), that meets the requirements, and "No"otherwise.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
3 votes
Tags:
MathematicsEasy-MediumGreatest common divisorNumber Theory
Points:30
4 votes
Tags:
MathematicsDynamic ProgrammingEasy-MediumNumber Theory
Points:30
1 votes
Tags:
Easy-MediumEasy-Medium