Problem list
Log in
#r03203 · Online Judge > GoldOJ

Reverse Collatz Path

Bronze II 2.0 s 256 MB

Apply the Collatz process to $n$ (odd $\to 3n+1$, even $\to n/2$) until it reaches $1$. Print the whole path but in reverse: starting from $1$ and ending at the original $n$, one value per line.

Input

One integer $n$ ($1 \le n \le 10^7$).

Output

Print the Collatz path from $1$ back up to $n$, one per line.

Example 1

Input
5
Output
1
2
4
8
16
5
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code