codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1864C.md (2067B)


      1 Source: https://codeforces.com/problemset/problem/1864/C
      2 
      3 C. Divisor Chain
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given an integer $x$. Your task is to reduce $x$ to $1$.
     22 
     23 To do that, you can do the following operation:
     24 
     25 * 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 \cdot q$.)
     26 
     27 There is an additional constraint: you cannot select the same value of $d$ more than twice.
     28 
     29 For example, for $x=5$, the following scheme is invalid because $1$ is selected more than twice: $5\xrightarrow{-1}4\xrightarrow{-1}3\xrightarrow{-1}2\xrightarrow{-1}1$. The following scheme is however a valid one: $5\xrightarrow{-1}4\xrightarrow{-2}2\xrightarrow{-1}1$.
     30 
     31 Output any scheme which reduces $x$ to $1$ with at most $1000$ operations. It can be proved that such a scheme always exists.
     32 
     33 Input
     34 
     35 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.
     36 
     37 The only line of each test case contains a single integer $x$ ($2\le x \le 10^{9}$).
     38 
     39 Output
     40 
     41 For each test case, output two lines.
     42 
     43 The first line should contain an integer $k$ ($1 \le k \le 1001$).
     44 
     45 The next line should contain $k$ integers $a_1,a_2,\ldots,a_k$, which satisfy the following:
     46 
     47 * $a_1=x$;
     48 * $a_k=1$;
     49 * for each $2 \le i \le k$, the value $(a_{i-1}-a_i)$ is a divisor of $a_{i-1}$. Each number may occur as a divisor at most twice.
     50 
     51 Example
     52 
     53 Input
     54 
     55 ```
     56 3
     57 
     58 3
     59 
     60 5
     61 
     62 14
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 3
     69 3 2 1
     70 4
     71 5 4 2 1
     72 6
     73 14 12 6 3 2 1
     74 ```
     75 
     76 Note
     77 
     78 In the first test case, we use the following scheme: $3\xrightarrow{-1}2\xrightarrow{-1}1$.
     79 
     80 In the second test case, we use the following scheme: $5\xrightarrow{-1}4\xrightarrow{-2}2\xrightarrow{-1}1$.
     81 
     82 In the third test case, we use the following scheme: $14\xrightarrow{-2}12\xrightarrow{-6}6\xrightarrow{-3}3\xrightarrow{-1}2\xrightarrow{-1}1$.