#K13306. Collatz Sequence Length
Collatz Sequence Length
Collatz Sequence Length
In this problem, you are given a positive integer (S) and are required to compute the length of its Collatz sequence. The Collatz sequence is defined as follows:
- Start with an integer (S).
- If (S = 1), the sequence terminates.
- If (S) is even, then update (S = \frac{S}{2}) (i.e., divide by 2).
- If (S) is odd and greater than 1, then update (S = 3S + 1).
The process continues until (S) becomes 1. Your task is to calculate the total number of terms in this sequence (including the starting number and 1) for each test case.
For example, when (S = 3), the sequence is: 3, 10, 5, 16, 8, 4, 2, 1, which has 8 terms.
inputFormat
The first line of input contains an integer (T) (the number of test cases). Each of the next (T) lines contains a single integer (S) (\left(1 \leq S \leq 10^9\right)), representing the starting number of a Collatz sequence.
outputFormat
For each test case, output a single integer denoting the length of the Collatz sequence starting from (S). Each answer should be printed on its own line.## sample
5
1
2
3
4
5
1
2
8
3
6
</p>