CF1864C.Divisor Chain

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an integer xx. Your task is to reduce xx to 11.

To do that, you can do the following operation:

  • select a divisor dd of xx, then change xx to x−dx-d, i.e. reduce xx by dd. (We say that dd is a divisor of xx if dd is an positive integer and there exists an integer qq such that x=d⋅qx = d \cdot q.)

There is an additional constraint: you cannot select the same value of dd more than twice.

For example, for x=5x=5, the following scheme is invalid because 11 is selected more than twice: 5→−14→−13→−12→−115\xrightarrow{-1}4\xrightarrow{-1}3\xrightarrow{-1}2\xrightarrow{-1}1. The following scheme is however a valid one: 5→−14→−22→−115\xrightarrow{-1}4\xrightarrow{-2}2\xrightarrow{-1}1.

Output any scheme which reduces xx to 11 with at most 10001000 operations. It can be proved that such a scheme always exists.

给你一个整数 xx。你的任务是将 xx 减少至 11。

为此,你可以执行以下操作:

  • 选择 xx 的一个约数 dd,然后将 xx 变为 x−dx-d,即用 dd 减少 xx。(我们称 dd 是 xx 的约数,当且仅当 dd 是正整数,且存在整数 qq 使得 x=d⋅qx = d \cdot q。)

还有一个附加约束:同一个 dd 值最多只能被选择两次。

例如,对 x=5x=5,如下方案是无效的,因为 11 被选用了超过两次:
5→−14→−13→−12→−115\xrightarrow{-1}4\xrightarrow{-1}3\xrightarrow{-1}2\xrightarrow{-1}1。
而如下方案是有效的:
5→−14→−22→−115\xrightarrow{-1}4\xrightarrow{-2}2\xrightarrow{-1}1。

请输出任意一种将 xx 减少至 11 的方案,且操作次数不超过 10001000 次。可以证明这样的方案总是存在的。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001 \le t \le 1000). The description of the test cases follows.

The only line of each test case contains a single integer xx (2≤x≤1092\le x \le 10^{9}).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10001 \le t \le 1000)。随后是各测试用例的描述。

每个测试用例仅有一行,包含一个整数 xx(2≤x≤1092\le x \le 10^{9})。

输出格式

For each test case, output two lines.

The first line should contain an integer kk (1≤k≤10011 \le k \le 1001).

The next line should contain kk integers a1,a2,…,aka_1,a_2,\ldots,a_k, which satisfy the following:

  • a1=xa_1=x;
  • ak=1a_k=1;
  • for each 2≤i≤k2 \le i \le k, the value (ai−1−ai)(a_{i-1}-a_i) is a divisor of ai−1a_{i-1}. Each number may occur as a divisor at most twice.

对于每个测试用例,输出两行。

第一行应包含一个整数 kk(1≤k≤10011 \le k \le 1001)。

下一行应包含 kk 个整数 a1,a2,…,aka_1,a_2,\ldots,a_k,满足以下条件:

  • a1=xa_1=x;
  • ak=1a_k=1;
  • 对每个 2≤i≤k2 \le i \le k,差值 (ai−1−ai)(a_{i-1}-a_i) 是 ai−1a_{i-1} 的一个因数。每个数作为因数至多出现两次。

输入输出样例

  • 输入#1

    3
    3
    5
    14

    输出#1

    3
    3 2 1
    4
    5 4 2 1
    6
    14 12 6 3 2 1

说明/提示

In the first test case, we use the following scheme: 3→−12→−113\xrightarrow{-1}2\xrightarrow{-1}1.

In the second test case, we use the following scheme: 5→−14→−22→−115\xrightarrow{-1}4\xrightarrow{-2}2\xrightarrow{-1}1.

In the third test case, we use the following scheme: 14→−212→−66→−33→−12→−1114\xrightarrow{-2}12\xrightarrow{-6}6\xrightarrow{-3}3\xrightarrow{-1}2\xrightarrow{-1}1.

在第一个测试用例中,我们使用以下方案:3→−12→−113\xrightarrow{-1}2\xrightarrow{-1}1。

在第二个测试用例中,我们使用以下方案:5→−14→−22→−115\xrightarrow{-1}4\xrightarrow{-2}2\xrightarrow{-1}1。

在第三个测试用例中,我们使用以下方案:14→−212→−66→−33→−12→−1114\xrightarrow{-2}12\xrightarrow{-6}6\xrightarrow{-3}3\xrightarrow{-1}2\xrightarrow{-1}1。

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

首页