Category
Similar Problems
0705. Inverse problem to Gray code
Time limit : 1000 ms
Memory limit : 64 mb
One can determine the Gray code by its number using a very simple function: G(x) = x xor (x div 2), where xor stands for bitwise exclusive OR (bitwise modulo 2 addition), and div means integer division. It is interesting to note that function G(x) is invertible, which means it is always possible to uniquely restore x given the value of G(x). Write a program to restore number x from the given value of G(x).
Input
The input file contains an integer number y, the value of G(x) (0≤y≤109).
Output
The output file should contain a single integer x such that G(x) = y.
Samples
№ |
Input |
Output |
1 |
15 |
10 |
2 |
1723 |
1234 |
3 |
0 |
0 |
Text from: Moscow subregional