#K64062. Collatz Conjecture Steps
Collatz Conjecture Steps
Collatz Conjecture Steps
In this problem, you are given a positive integer (n). Your task is to compute the number of steps required to reduce (n) to 1 by following the rules of the Collatz Conjecture. The rules are as follows:
- If \(n\) is even, then the next number is \(\frac{n}{2}\).
- If \(n\) is odd, then the next number is \(3n+1\).
You must apply these operations repeatedly until (n) becomes 1. For example, starting with (n=6), the sequence is: 6, 3, 10, 5, 16, 8, 4, 2, 1. The number of steps here is 8. The problem is designed to test your ability in simulation and basic algorithm implementation.
inputFormat
The input is provided via standard input (stdin). The first line contains an integer (T) representing the number of test cases. Each of the following (T) lines contains a single positive integer (n).
outputFormat
For each test case, output on a new line the number of steps required for (n) to become 1 following the Collatz Conjecture process.## sample
1
1
0
</p>