Gray Code: Cyclic Shift and XOR
C++
Hard
loops
Task «Gray Code: Cyclic Shift and XOR»
Given an integer N (1 ≤ N ≤ 20). Generate a sequence of 2^N numbers representing the Gray code for numbers from 0 to 2^N-1. Then, for each number in this sequence, perform a cyclic shift of its binary representation to the right by 1 bit and apply the XOR operation with the original number. Output the resulting values in ascending order of the original numbers. Use only loops and bitwise operations, avoiding recursion.
Input Format
One integer N (1 ≤ N ≤ 20).
Output Format
2^N integers separated by spaces, each on a new line.
Examples
Example 1
INPUT
3
1 2 3
4 5 6
7 8 9
OUTPUT
15
Example 2
INPUT
1 5
OUTPUT
1 2 4 8 16
Example 3
INPUT
5
1 2 3 4 5
2 3
OUTPUT
12
Example 4
INPUT
3
OUTPUT
1
0
0
2
0
4
4
6
main.cpp