CF1810B.Candies

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This problem is about candy. Initially, you only have 11 candy, and you want to have exactly nn candies.

You can use the two following spells in any order at most 4040 times in total.

  • Assume you have xx candies now. If you use the first spell, then xx candies become 2x−12x-1 candies.
  • Assume you have xx candies now. If you use the second spell, then xx candies become 2x+12x+1 candies.

Construct a sequence of spells, such that after using them in order, you will have exactly nn candies, or determine it's impossible.

这个问题关于糖果。初始时,你只有 11 颗糖果,而你的目标是恰好拥有 nn 颗糖果。

你可以按任意顺序使用以下两种法术,总共至多使用 4040 次。

  • 假设你现在有 xx 颗糖果。若使用第一种法术,则 xx 颗糖果变为 2x−12x-1 颗糖果。
  • 假设你现在有 xx 颗糖果。若使用第二种法术,则 xx 颗糖果变为 2x+12x+1 颗糖果。

请构造一个法术序列,使得按该顺序使用后,你恰好拥有 nn 颗糖果;或者判断这是不可能的。

输入格式

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

Each test case contains one line with a single integer nn (2≤n≤1092 \le n \le 10^9) — the required final number of candies.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。随后是这些测试用例的描述。

每个测试用例包含一行,其中有一个整数 nn(2≤n≤1092 \le n \le 10^9),表示所需的最终糖果数量。

输出格式

For each test case, output the following.

If it's possible to eventually have nn candies within 4040 spells, in the first line print an integer mm (1≤m≤401 \le m \le 40), representing the total number of spells you use.

In the second print mm integers a1,a2,…,ama_{1}, a_{2}, \ldots, a_{m} (aia_{i} is 11 or 22) separated by spaces, where ai=1a_{i} = 1 means that you use the first spell in the ii-th step, while ai=2a_{i} = 2 means that you use the second spell in the ii-th step.

Note that you do not have to minimize mm, and if there are multiple solutions, you may output any one of them.

If it's impossible, output −1-1 in one line.

对于每个测试用例,输出如下内容:

如果能在至多 4040 次法术内最终恰好获得 nn 颗糖果,则在第一行输出一个整数 mm(1≤m≤401 \le m \le 40),表示你所使用的法术总次数。

在第二行输出 mm 个整数 a1,a2,…,ama_{1}, a_{2}, \ldots, a_{m}(每个 aia_{i} 为 11 或 22),以空格分隔;其中 ai=1a_{i} = 1 表示在第 ii 步使用第一个法术,而 ai=2a_{i} = 2 表示在第 ii 步使用第二个法术。

注意:你无需最小化 mm;若存在多种解,输出任意一种即可。

如果不可能实现,则在一行中输出 −1-1。

输入输出样例

  • 输入#1

    4
    2
    3
    7
    17

    输出#1

    -1
    1
    2 
    2
    2 2 
    4
    2 1 1 1

说明/提示

For n=3n=3, you can just use the second spell once, and then have 2⋅1+1=32 \cdot 1 + 1 = 3 candies.

For n=7n=7, you can use the second spell twice. After the first step, you will have 33 candies. And after the second step, you will have 2⋅3+1=72 \cdot 3 + 1 = 7 candies.

当 n=3n=3 时,只需使用一次第二种法术,即可得到 2⋅1+1=32 \cdot 1 + 1 = 3 颗糖果。

当 n=7n=7 时,可以使用两次第二种法术。第一次操作后,你将拥有 33 颗糖果;第二次操作后,你将拥有 2⋅3+1=72 \cdot 3 + 1 = 7 颗糖果。

输入解题思路,AI测评打分。不知道怎么写?

首页