Problems > Collatz Steps

Collatz Steps

Difficulty: 1000 2000 ms 128 MB

math implementation

Repeatedly apply: even N → N/2, odd N → 3N+1. Print the number of steps to reach 1.

Input: one integer N.

Output: the step count.

Constraints:

  • 1 ≤ N ≤ 106

Sample Tests

Input 1
6
Output 1
8
Input 2
1
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.