Rectangle matrices
Practice
4.5 (10 votes)
Algorithms
String manipulation
Problem
60% Success 1600 Attempts 10 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given a rectangle matrix of size \(10^{18} \times 10^{18}\). The rows of the matrix are numbered \(1\) to \(10^{18}\) from top to bottom and the columns of the matrix are numbered \(1\) to \(10^{18}\) from left to right. The cell of the field at the intersection of the \(x^{th}\) row and \(y^{th}\) column is represented by \((x,y)\)

A rabbit is standing at cell \((1,1)\). The rabbit can move from a cell \((x,y)\) to a cell \((2\times x,y)\) or \((x,2\times y) \) in a few seconds because of its good speed. Also, it can move to \((x,y-x)\) or \((x-y,y)\)

Note: The rabbit cannot move out of the bounds of the matrix.

You purchase food for the rabbit for the next \(q\) days. You place the food in the cell \((x_i, y_i)\) on the \(i^{th}\) day but you are unsure if these cells are reachable. Your task is to determine if you can reach from the cell \((1,1)\) to the cell \((x_i, y_i)\).

Input format

  • First line: Integer \(q\) denoting the number of days
  • Next \(q\) lines: Two space-separated integers \(x_i\) and \(y_i\) denoting the coordinates where the food is placed

Output format

For each of \(q\) days, print Yes in a single line if there is a path from cell \((1,1)\) to cell \((x_i, y_i)\) ensuring all the requirements are met. If it is not possible, print No.

Constraints

\(1 \le q \le 3\times 10^5 \\ 1 \le x_i, y_i \le 10^{18}\)

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:10
57 votes
Tags:
AlgorithmsString Manipulation
Points:10
25 votes
Tags:
AlgorithmsEasyString Manipulation