#C2648. Alice's Number Transformation
Alice's Number Transformation
Alice's Number Transformation
In this problem, you are given a positive integer \(n\) and a maximum allowed step count \(S\). You need to perform a transformation on \(n\) until it becomes 1. The transformation is defined as follows:
- If \(n\) is even, then update \(n \leftarrow \frac{n}{2}\).
- If \(n\) is odd and \(n \neq 1\), then update \(n \leftarrow 3n + 1\).
Count the number of steps taken. If the number of steps required to reach 1 exceeds \(S\), output Too Long
; otherwise, output the number of steps.
You will be given multiple test cases. For each test case, output the result on a new line.
Note: The mathematical formulas used in the transformation are given by:
Even case: \(n \leftarrow \frac{n}{2}\) and Odd case: \(n \leftarrow 3n+1\).
inputFormat
The first line contains an integer \(T\), the number of test cases. Each of the next \(T\) lines contains two space-separated values: a positive integer \(n\) and an integer \(S\), the maximum allowed number of steps.
Example:
3 6 10 15 20 3 5
outputFormat
For each test case, output the number of steps needed for the transformation to reach 1 if it does not exceed \(S\); otherwise, output Too Long
. Each result should be printed on a new line.
Example:
8 17 Too Long## sample
3
6 10
15 20
3 5
8
17
Too Long
</p>