#K51532. Collatz Conjecture Steps

    ID: 29108 Type: Default 1000ms 256MiB

Collatz Conjecture Steps

Collatz Conjecture Steps

Given a positive integer \(n\) (where \(1 \le n \le 10^6\)), perform the following operations until \(n\) becomes 1:

  • If \(n\) is even: \(n \gets \frac{n}{2}\)
  • If \(n\) is odd: \(n \gets 3n+1\)

Count the number of steps required for \(n\) to become 1. For example, when \(n=6\), the sequence is: 6 \(\to\) 3 \(\to\) 10 \(\to\) 5 \(\to\) 16 \(\to\) 8 \(\to\) 4 \(\to\) 2 \(\to\) 1, which takes 8 steps.

inputFormat

The input consists of a single integer \(n\) provided via standard input.

Constraints: \(1 \le n \le 10^6\).

outputFormat

Output a single integer representing the number of steps needed for \(n\) to become 1. The result should be printed to standard output.

## sample
6
8