Collatz Steps

Lab Python Intermediate 20 points

Read a positive integer n. Repeatedly: if even, halve it; if odd, make it 3n+1. Print how many steps it takes to reach 1.

Input

One integer ≥ 1.

Output

The number of steps.

Example

Input

6

Output

8
Sample input available Sample output available
Editor
Python

Hints

Loop while n != 1.

Use // so n stays an integer.

Solution explanation

27 takes 111 steps — a classic example of a loop whose length is hard to predict.

Show solution
n = int(input())
steps = 0
while n != 1:
    n = n // 2 if n % 2 == 0 else 3 * n + 1
    steps += 1
print(steps)
Output
Answer
HOME LEARN COMMUNITY DASHBOARD