You are given an integer $$N$$. To solve the problem, you must find the minimum number of elements that must be removed from the set $$S = \lbrace 1, 2, ..., N \rbrace $$ such that the bitwise XOR of the remaining elements is $$0$$.
Input format
- The first line contains an integer $$t (1 \leq t \leq 10^5)$$ representing the number of test cases.
- The first and only line of each test case contains an integer $$N (1 \leq N \leq 10^9)$$ representing the number presented to you.
Output format
For each test case, print a single line.
The first integer $$k$$ represents the minimum number of elements and you must remove from $$S$$. Then, $$k$$ space-separated integers $$a_1, a_2, ..., a_k$$ follows representing the elements that you have to remove from $$S$$.
If there are multiple possible solutions, output the lexicographically largest one. A solution $$a_1, a_2, ..., a_k$$ is lexicographically larger than solution $$b_1, b_2, ..., b_k$$, if $$a_i > b_i$$ where $$i$$ is the smallest index where $$a_i \neq b_i$$.
It can be proved that in an optimal solution $$k \leq 31$$.
After removing 1 there are no elements left. Therefore XOR of the remaining elements becomes 0.
After removing 1 and 2 there are no elements left. Therefore XOR of the remaining elements becomes 0.
We don't need to remove any element as XOR of 1, 2, and 3 is already 0.
After removing 4 we are left with 1,2 and 3 whose XOR is 0.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor