Codeforces Round 958 (Div. 2)
C
Increasing Sequence with Fixed OR
Codeforces
1300
原题
← BD →
翻译中…

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

翻译中…
  • $a_i\le n$ for all $1\le i\le k$.
  • $a$ is strictly increasing. That is, $a_i \gt a_{i-1}$ for all $2\le i\le k$.
  • $a_i\,|\,a_{i-1}=n$ for all $2\le i\le k$, where $|$ denotes the bitwise OR operation.
翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). Description of the test cases follows.

翻译中…

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

翻译中…

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

翻译中…

Output

翻译中…

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

翻译中…

样例

Input #1
4
1
3
14
23
Output #1
1
1
3
1 2 3
4
4 10 12 14
5
7 18 21 22 23
InputCopy OutputCopy
题目信息
题号
1988C
时间限制
2 s
内存限制
512 MB
标签
位运算
构造
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。