#P9635. Constructing a Special XOR Sequence
Constructing a Special XOR Sequence
Constructing a Special XOR Sequence
You are given an integer n. Your task is to construct a sequence of n distinct positive integers \(\{a_i\}\) such that:
- The bitwise XOR of all elements is equal to \(n\): \(a_1 \oplus a_2 \oplus \cdots \oplus a_n = n\). (Here \(\oplus\) denotes the bitwise XOR operation.)
- The sum of all elements does not exceed \(n^2\): \(\displaystyle\sum_{i=1}^n a_i \le n^2\).
If there is no such sequence, output -1
. In case there are multiple answers, you can output any one of them.
Note: This problem is evaluated by Special Judge.
You need to answer T
test cases.
inputFormat
The first line contains a single integer T
(\(1 \le T \le 10^5\)), the number of test cases.
Each of the next T
lines contains a single integer n
(\(1 \le n \le 10^9\)).
outputFormat
For each test case, if a valid sequence exists, output a single line containing n
space-separated integers \(a_1, a_2, \dots, a_n\) satisfying the conditions. Otherwise, output -1
.
Special Judge: Your output will be accepted if it meets all the required conditions.
sample
1
1
1
</p>