CF1864C.Divisor Chain
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer x. Your task is to reduce x to 1.
To do that, you can do the following operation:
- select a divisor d of x, then change x to x−d, i.e. reduce x by d. (We say that d is a divisor of x if d is an positive integer and there exists an integer q such that x=d⋅q.)
There is an additional constraint: you cannot select the same value of d more than twice.
For example, for x=5, the following scheme is invalid because 1 is selected more than twice: 5−14−13−12−11. The following scheme is however a valid one: 5−14−22−11.
Output any scheme which reduces x to 1 with at most 1000 operations. It can be proved that such a scheme always exists.
给你一个整数 x。你的任务是将 x 减少至 1。
为此,你可以执行以下操作:
- 选择 x 的一个约数 d,然后将 x 变为 x−d,即用 d 减少 x。(我们称 d 是 x 的约数,当且仅当 d 是正整数,且存在整数 q 使得 x=d⋅q。)
还有一个附加约束:同一个 d 值最多只能被选择两次。
例如,对 x=5,如下方案是无效的,因为 1 被选用了超过两次:
5−14−13−12−11。
而如下方案是有效的:
5−14−22−11。
请输出任意一种将 x 减少至 1 的方案,且操作次数不超过 1000 次。可以证明这样的方案总是存在的。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤1000). The description of the test cases follows.
The only line of each test case contains a single integer x (2≤x≤109).
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤1000)。随后是各测试用例的描述。
每个测试用例仅有一行,包含一个整数 x(2≤x≤109)。
输出格式
For each test case, output two lines.
The first line should contain an integer k (1≤k≤1001).
The next line should contain k integers a1,a2,…,ak, which satisfy the following:
- a1=x;
- ak=1;
- for each 2≤i≤k, the value (ai−1−ai) is a divisor of ai−1. Each number may occur as a divisor at most twice.
对于每个测试用例,输出两行。
第一行应包含一个整数 k(1≤k≤1001)。
下一行应包含 k 个整数 a1,a2,…,ak,满足以下条件:
- a1=x;
- ak=1;
- 对每个 2≤i≤k,差值 (ai−1−ai) 是 ai−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−11.
In the second test case, we use the following scheme: 5−14−22−11.
In the third test case, we use the following scheme: 14−212−66−33−12−11.
在第一个测试用例中,我们使用以下方案:3−12−11。
在第二个测试用例中,我们使用以下方案:5−14−22−11。
在第三个测试用例中,我们使用以下方案:14−212−66−33−12−11。
输入解题思路,AI测评打分。不知道怎么写?