#P5727. Reverse Collatz Sequence

    ID: 18955 Type: Default 1000ms 256MiB

Reverse Collatz Sequence

Reverse Collatz Sequence

Given a positive integer \(n\), perform the following operation repeatedly: if the number is odd, multiply it by \(3\) and add \(1\), otherwise divide it by \(2\). The sequence will eventually reach \(1\) (this is known as the Collatz Conjecture or hailstone conjecture). After computing the sequence starting from \(n\) and ending at \(1\), output the entire sequence in reverse order (i.e., starting from \(1\) up to \(n\)).

For example, if \(n = 20\), the sequence is:

[ 20 \to 10 \to 5 \to 16 \to 8 \to 4 \to 2 \to 1 ]

The output should be:

[ 1; 2; 4; 8; 16; 5; 10; 20 ]

</p>

inputFormat

The input consists of a single positive integer \(n\) (\(1 \leq n \leq 10^{18}\)).

outputFormat

Output the reversed Collatz sequence. The numbers should be separated by a single space.

sample

20
1 2 4 8 16 5 10 20