CF1864C.Divisor Chain
普及/提高-
通过率:0%
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.
输入格式
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 ).
输出格式
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.
输入输出样例
输入#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 .