Problem I
Grey Codes
Input: Standard Input
Output: Standard Output
|
Gray hair is God's graffiti. |
Bill
Cosby
We are going to generate a sequence of integers in binary. Start with the sequence
|
0 |
|
|
Reflect it in the horizontal line, prepend a zero to
the numbers in the top half and a one to the numbers on the bottom and you will
get
|
00 |
Repeat this again, and you will have 8 numbers
|
000 |
|
0 |
The corresponding decimal values are shown on the right.
These sequences are called Reflected
Gray Codes for 1, 2 and 3 bits respectively. A Gray Code for n bits is a
sequence of
The first line of input gives the number of cases, N
(at most 250000). N test cases follow. Each one is a line with 2
integers: n
For each test case, output the
integer that appears in position k of the
141 01 12 02 12 22 33 03 13 23 33 43 53 63 7 |
01013201326754 |
Problem
setter: Igor Naverniouk