311380: CF1977B. Binary Colouring

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Binary Colouringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given a positive integer $x$. Find any array of integers $a_0, a_1, \ldots, a_{n-1}$ for which the following holds:

  • $1 \le n \le 32$,
  • $a_i$ is $1$, $0$, or $-1$ for all $0 \le i \le n - 1$,
  • $x = \displaystyle{\sum_{i=0}^{n - 1}{a_i \cdot 2^i}}$,
  • There does not exist an index $0 \le i \le n - 2$ such that both $a_{i} \neq 0$ and $a_{i + 1} \neq 0$.

It can be proven that under the constraints of the problem, a valid array always exists.

Input

Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.

The only line of each test case contains a single positive integer $x$ ($1 \le x < 2^{30}$).

Output

For each test case, output two lines.

On the first line, output an integer $n$ ($1 \le n \le 32$) — the length of the array $a_0, a_1, \ldots, a_{n-1}$.

On the second line, output the array $a_0, a_1, \ldots, a_{n-1}$.

If there are multiple valid arrays, you can output any of them.

ExampleInput
7
1
14
24
15
27
11
19
Output
1
1
5
0 -1 0 0 1
6
0 0 0 -1 0 1
5
-1 0 0 0 1
6
-1 0 -1 0 0 1
5
-1 0 -1 0 1
5
-1 0 1 0 1
Note

In the first test case, one valid array is $[1]$, since $(1) \cdot 2^0 = 1$.

In the second test case, one possible valid array is $[0,-1,0,0,1]$, since $(0) \cdot 2^0 + (-1) \cdot 2^1 + (0) \cdot 2^2 + (0) \cdot 2^3 + (1) \cdot 2^4 = -2 + 16 = 14$.

Output

题目大意:
这个题目是关于二进制着色的。给定一个正整数 x,需要找到一个整数数组 a_0, a_1, ..., a_{n-1},满足以下条件:
1. 1 ≤ n ≤ 32,
2. 对于所有 0 ≤ i ≤ n - 1,a_i 是 1、0 或 -1,
3. x = Σ_{i=0}^{n - 1} a_i * 2^i,
4. 不存在一个索引 0 ≤ i ≤ n - 2,使得 a_i ≠ 0 和 a_{i + 1} ≠ 0。

题目保证在这些约束条件下,总是存在一个有效的数组。

输入输出数据格式:
输入:
每个测试包含多个测试用例。输入的第一行包含一个整数 t (1 ≤ t ≤ 10^4) — 测试用例的数量。接下来是每个测试用例的描述。
每个测试用例只有一行,包含一个正整数 x (1 ≤ x < 2^{30})。

输出:
对于每个测试用例,输出两行。
第一行输出一个整数 n (1 ≤ n ≤ 32) — 数组 a_0, a_1, ..., a_{n-1} 的长度。
第二行输出数组 a_0, a_1, ..., a_{n-1}。
如果有多个有效的数组,可以输出其中任何一个。题目大意: 这个题目是关于二进制着色的。给定一个正整数 x,需要找到一个整数数组 a_0, a_1, ..., a_{n-1},满足以下条件: 1. 1 ≤ n ≤ 32, 2. 对于所有 0 ≤ i ≤ n - 1,a_i 是 1、0 或 -1, 3. x = Σ_{i=0}^{n - 1} a_i * 2^i, 4. 不存在一个索引 0 ≤ i ≤ n - 2,使得 a_i ≠ 0 和 a_{i + 1} ≠ 0。 题目保证在这些约束条件下,总是存在一个有效的数组。 输入输出数据格式: 输入: 每个测试包含多个测试用例。输入的第一行包含一个整数 t (1 ≤ t ≤ 10^4) — 测试用例的数量。接下来是每个测试用例的描述。 每个测试用例只有一行,包含一个正整数 x (1 ≤ x < 2^{30})。 输出: 对于每个测试用例,输出两行。 第一行输出一个整数 n (1 ≤ n ≤ 32) — 数组 a_0, a_1, ..., a_{n-1} 的长度。 第二行输出数组 a_0, a_1, ..., a_{n-1}。 如果有多个有效的数组,可以输出其中任何一个。

加入题单

上一题 下一题 算法标签: