3n+1

View as PDF

Points: 3
Time limit: 1.0s
Memory limit: 16M

Problem type

Pick a positive integer . If it is odd, multiply it by three and then add one. Otherwise (if it is even), divide it by two. The positive integer obtained is the new , and this procedure is repeated.

It is believed that will eventually become (this is called the Collatz conjecture.) Computers have checked that any value of less than does, indeed, eventually become if this procedure is applied enough times.

You will be given the value of . Determine how many times this procedure must be applied before becomes .

Input Specification

The initial value of .

Output Specification

The number of operations we have to perform on before it becomes .

Constraints

Any value of , initial or intermediate, will be less than .

Sample Input

7

Sample Output

16

Explanation

will go through these steps:

• commented on Oct. 28, 2020, 9:23 a.m.

The test data is very weak. 0 < n < 35655.

• commented on May 10, 2022, 6:15 p.m.

Genuine question.

How do you check the test data?

It would help me solve other problems, I think...

Thanks!

• commented on Sept. 26, 2022, 7:06 p.m.

You don't, unless the problem originated from somewhere else