CF BUDDY
← Problems·

1988C · Increasing Sequence with Fixed OR

1300 · bitmasks, constructive algorithms, greedy

Problem: You are given a positive integer nn. Find the longest sequence of positive integers a=[a1,a2,,ak]a=[a_1,a_2,\ldots,a_k] that satisfies the following conditions, and print the sequence:

  • aina_i\le n for all 1ik1\le i\le k.
  • aa is strictly increasing. That is, ai>ai1a_i>a_{i-1} for all 2ik2\le i\le k.
  • aiai1=na_i\,|\,a_{i-1}=n for all 2ik2\le i\le k, where | denotes the bitwise OR operation.

Input Format: Each test contains multiple test cases. The first line contains the number of test cases tt (1t10001 \le t \le 1000). Description of the test cases follows.

The only line of each test case contains one integer nn (1n10181\le n\le 10^{18}).

It's guaranteed that the sum of lengths of the longest valid sequences does not exceed 51055\cdot 10^5.

Output Format: For each testcase, print two lines. In the first line, print the length of your constructed sequence, kk. In the second line, print kk positive integers, denoting the sequence. If there are multiple longest sequences, you can print any of them.

Sample Cases

Case 1

Input

4
1
3
14
23

Output

1
1
3
1 2 3
4
4 10 12 14
5
7 18 21 22 23

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback