Hide

Problem D
Collatz Conjecture

Accepted submissions to this problem will be granted a score of 100

Let a be a positive integer and consider the sequence where x0=a and

xn+1={xn/2if xn is even3xn+1if xn is odd

The Collatz conjecture states that this sequence will always reach 1.

For example, if a=10, then x0=10,x1=5,x2=16,x3=8,x4=4,x5=2 and x6=1.

Write a program that reads a positive integer from the user and, using a while loop, outputs each element of the above sequence until it reaches 1.

Input

Input consists of one line with one integer x0, the initial term of the sequence, where 0x0100000.

Output

Output consists of one or more lines, where the ith line contains the integer xi, for i0.

Sample Input 1 Sample Output 1
2
2
1
Sample Input 2 Sample Output 2
3
3
10
5
16
8
4
2
1
Sample Input 3 Sample Output 3
19
19
58
29
88
44
22
11
34
17
52
26
13
40
20
10
5
16
8
4
2
1
Sample Input 4 Sample Output 4
25
25
76
38
19
58
29
88
44
22
11
34
17
52
26
13
40
20
10
5
16
8
4
2
1
Hide

Please log in to submit a solution to this problem

Log in