Perfect Triples
Time limit2sMemory limit1024 MB
Given n up to 1e16, find the n-th element of a sequence built by repeatedly appending the lexicographically smallest unused triple with XOR zero.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Math
- Solved
- No attempts yet
Problem
Consider the infinite sequence of positive integers, created by repeating the following steps:
-
Find the lexicographically smallest triple of positive integers such that
- , where denotes the bitwise XOR operation.
- , , are not in .
A triple is lexicographically smaller than if the sequence is lexicographically smaller than .
-
Append , , to in this order.
-
Go back to the first step.
You have integer . Find the -th element of .
You have to answer independent test cases.
A sequence is lexicographically smaller than a sequence if, at the first position where and differ, the element of is smaller than the corresponding element of .
Input
The first line contains a single integer (), the number of test cases.
Each of the next lines contains a single integer (), the position of the element you want to know.
Output
For each test case, output the answer on its own line.
Hint
The first elements of are