CF1864C.Divisor Chain

普及/提高-

通过率:0%

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 xdx-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=dqx = 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: 5141312115\xrightarrow{-1}4\xrightarrow{-1}3\xrightarrow{-1}2\xrightarrow{-1}1 . The following scheme is however a valid one: 51422115\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.

输入格式

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

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

输出格式

For each test case, output two lines.

The first line should contain an integer kk ( 1k10011 \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 2ik2 \le i \le k , the value (ai1ai)(a_{i-1}-a_i) is a divisor of ai1a_{i-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: 312113\xrightarrow{-1}2\xrightarrow{-1}1 .

In the second test case, we use the following scheme: 51422115\xrightarrow{-1}4\xrightarrow{-2}2\xrightarrow{-1}1 .

In the third test case, we use the following scheme: 142126633121114\xrightarrow{-2}12\xrightarrow{-6}6\xrightarrow{-3}3\xrightarrow{-1}2\xrightarrow{-1}1 .

首页