Collatz Beauty#12259

Collatz Beauty (Editorial)

Problem Author:

Hasan Saleh (MathModel)

Prepared by:

Hasan Saleh (MathModel)

Edited by:

Hasan Saleh (MathModel)

Solution

Simulate the process for given , and count the number of performed operations of type .

While there's no official accurate bounding for Collatz Conjecture.

It's useful to remark the algorithm performance for n \le 10^4 , By testing the worst sequence length is : , The constant is small that even the worst case of 1000 \cdot 261 \approx 3 \cdot 10^5 is good to pass.

Complexity .

def f(x):
    ans=0
    while(x!=1):
        if(x%2==0):
            x//=2
            ans+=1
        else:
            x*=3
            x+=1
    return ans

for _ in range(int(input())):
    n=int(input())
    print(f(n))