Bear and Ladder
All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Bearland has infinitely many cities, numbered starting from 1. Some pairs of cities are connected with bidirectional roads:
- There are roads 1-2, 3-4, 5-6, 7-8, and so on (there is a road between cities 2*i+1 and 2*i+2 for every non-negative integer i).
- There are roads 1-3, 3-5, 5-7, 7-9, ... (between every two consecutive odd numbers).
- There are roads 2-4, 4-6, 6-8, 8-10, ... (between every two consecutive even numbers).
This is how the first few cities and roads between them look like:
You are given Q queries. In each query, for the given pair of different cities a and b, you should check if there is a road between them. For each query, print "YES" or "NO" accordingly.
The first line of the input contains an integer Q, denoting the number of queries.
Each of the following Q lines contains two distinct integers a and b, denoting two cities in one query.
For each query, output a single line containing the answer — "YES" if there is a road between the given cities a and b, and "NO" otherwise (without the quotes).
- 1 ≤ Q ≤ 1000
- 1 ≤ a, b ≤ 109
- a ≠ b
Input: 7 1 4 4 3 5 4 10 12 1 3 999999999 1000000000 17 2384823 Output: NO YES NO YES YES YES NO
In the example test, the answer is "YES" for pairs (4, 3), (10, 12), (1, 3) and (999999999, 1000000000). Roads 3-4 and 1-3 you can see on the drawing in the statement.
The answer is "NO" for example for a pair (1, 4), because there is no road between cities 1 and 4.
|Tags||cakewalk, errichto, ltime46|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.