All problems

Problem 232

Collatz Steps

Easy · 10 pts · Math, Simulation

Problem

Start with a positive integer N and repeat this step until N becomes 1: if N is even, divide it by 2; if N is odd, replace it with 3N + 1. Print the number of steps taken. If N is already 1, the answer is 0. The Collatz conjecture says every starting number eventually reaches 1, and it holds for all inputs here. The values can grow well beyond N along the way, so use 64-bit integers.

Input

A single integer N.

Output

Print the number of steps.

Constraints

1 <= N <= 1000000 (all values along the way fit in a 64-bit integer)

Example input

6

Example output

8

Explanation

From 6: 6 → 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1. Counting the arrows gives 8 steps.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Digital Root Next: GCD of an Array