problems / 282

Bob Reads Alice's Binary Note Backwards

easy bit-manipulation palindromes math 1000 ms · 256 MB

Bob Reads Alice's Binary Note Backwards

Alice likes to pass Bob notes in class, and every note holds a single positive integer written in binary, with no leading zeros. Bob, as usual, reads every note from right to left. So when Alice writes 6, the note says 110, Bob reads 011, and he thinks Alice meant 3. Sometimes they are lucky and Bob reads exactly the number Alice wrote.

Formally, for a positive integer n, write n in binary without leading zeros, reverse the string of bits, and read the result as a binary number (zeros that end up at the front after reversing are simply ignored). Call that value r(n). For each note, find r(n) and tell whether r(n) = n.

Input

The first line contains an integer q (1 ≤ q ≤ 10^5), the number of notes.

Each of the next q lines contains one integer n (1 ≤ n ≤ 10^18).

Output

For each note, print one line with the number Bob reads, r(n), followed by a space and YES if r(n) = n, or NO otherwise.

Notes

In the first example: 6 = 110 is read as 011 = 3. 5 = 101 reads the same both ways, and so does 1. 8 = 1000 is read as 0001 = 1. 11 = 1011 is read as 1101 = 13. 9 = 1001 reads the same both ways.

Numbers up to 10^18 do not fit in a 32-bit integer, so use a 64-bit type. r(n) never has more bits than n, so it fits too.

Example 1

Input

6
6
5
1
8
11
9

Output

3 NO
5 YES
1 YES
1 NO
13 NO
9 YES

Example 2

Input

5
576460752303423487
576460752303423488
576460752303423490
1099511627777
3

Output

576460752303423487 YES
1 NO
288230376151711745 NO
1099511627777 YES
3 YES

Hints · reveal one at a time if you're stuck

Hint 1

Bob starts reading at the rightmost bit of n. How do you get the rightmost bit of a number, and how do you remove it?

Hint 2

Each bit you peel off the bottom of n is the next digit of Bob's number, so build that number as you go, the same way you would reverse the decimal digits of a number. If you stop once n has no bits left, the zeros at the bottom of n become leading zeros and drop out on their own. Then compare against a saved copy of the original n.

report an issue Prefer your own editor? sooks prep 282 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.