The sequence of Collatz

Let nn be any strictly positive natural number. Consider the following process. If nn is an even number, we divide it by two. Otherwise, we multiply it by 3 and add 1 to it. When we reach 1, we stop. For instance, starting with 3, we obtain the sequence 3,10,5,16,8,4,2,1.3,~ 10,~ 5,~ 16,~ 8,~ 4,~ 2,~ 1 .

Since 1937 it is conjectured that this process ends for any initial nn, although nobody has been able to prove it. In this problem, we do not ask you for a proof. You only have to write a program that prints the number of steps that it takes to reach 1 for every given nn.

Input

Input consists of several natural numbers n1n \ge 1.

Output

For every nn, print how many steps are needed to reach 1. Suppose that this number is well defined, that is, that the conjecture of the statement is true.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T11:51:02.508Z

© Jutge.org, 2006–2026.
https://jutge.org