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
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.