Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/funksiya-kollats-eng-uzun

Collatz steps

Easy 1000 ms 128 MB 32%
Share

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.

A number goes into the function CollatzSteps, which returns the number of steps to reach 1

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

Sign in to submit a solution

Signing up is free and takes a minute.