#K66087. Minimum Operations to Transform to One
Minimum Operations to Transform to One
Minimum Operations to Transform to One
You are given an integer n
. Your task is to determine the minimum number of operations required to reduce n
to 1 using the following rules:
- If
n
is even, replacen
withn/2
. - If
n
is odd, replacen
with3n+1
.
This process is based on the famous Collatz Conjecture. Formally, the operations can be described as:
$$ n = \begin{cases} \frac{n}{2} & \text{if } n \equiv 0 \; (\bmod\;2), \\ 3n + 1 & \text{if } n \equiv 1 \; (\bmod\;2). \end{cases} $$
Determine and output the number of operations needed to transform n
into 1.
inputFormat
The input consists of a single integer n
(where n ≥ 1
), provided via standard input.
outputFormat
Output a single integer, which is the minimum number of operations required to transform n
into 1.
6
8