XOR Triples
Time limit5sMemory limit256 MB
Choose the largest subset of 1 to N with no three distinct values xoring to zero, breaking ties by smallest lexicographic order.
- Level
Medium5 of 10
- Topics
- Brute force, Bit manipulation
- Solved
- No attempts yet
Problem
Choose distinct integers from 1 to and collect them into one sequence. For every choice of three distinct chosen numbers , , , the value must not be 0, where is the bitwise exclusive or (XOR).
Find a sequence of maximum length that satisfies this condition.
Input
The first line contains the number of test cases ().
Each of the next lines contains one integer ().
Output
Print the answer for each test case on two lines.
- The first line holds the length of the sequence.
- The second line holds the sequence sorted in increasing order, separated by single spaces.
If several sequences reach the maximum length, print only the one that is lexicographically smallest after sorting in increasing order.