Functions
Function-43
Function-44
Function-45
~/algor $ cat problems/funksiya-kollats-eng-uzun
Collatz steps
Easy
1000 ms
128 MB
32%
Write a function CollatzSteps(x) that returns how many Collatz steps it takes to get from the positive integer $x$ to $1$. In one step an even number is divided by $2$ and an odd number is replaced by $3 * x + 1$.
Example 1: CollatzSteps(6) → 8 — $6 \to 3 \to 10 \to 5 \to 16 \to 8 \to 4 \to 2 \to 1$.
Example 2: CollatzSteps(1) → 0 — for $x = 1$ no steps are needed.
Write only the function body.
Input
One line with a positive integer $x$ — the argument of the function.
Output
The value returned by the function: an integer.
Note
$1 \le x \le 10^{6}$
Examples
Input #1
6
Output #1
8
Input #2
1
Output #2
0