Back
Close

Collatz Sequence Tricks

Statement

 Goal

For a given input integer n as start of the Collatz Sequence do:
n=n/2 for even n (divisible by 2) and
n=3*n+1 for odd n (not divisible by 2)
until n=1
Count the number of different n if takes to reach n=1 and use this number as a new start value for n and repeat the process one more time. Print the number of different n of that second Collatz-Sequence. In one Collatz-Sequence there are only different n values.

Example:
n=5
Sequence: 5->16->8->4->2->1
=> n=6
Sequence: 6->3->10->5->16->8->4->2->1
=> n=9 ==>The result is 9
Input
Line 1: An integer n as start for the first collatz sequence
Output
Line 1: An integer as result
Constraints
1 ≤ n ≤ 10000000
be careful, the values of n in a collatz-sequence can exceed this constraint on some iteration
Example
Input
5
Output
9

Game modes
Fastest, Shortest

Test cases
Example Test
Input
5
Output
9

Example Validator Validator
Input
5
Output
9

1 Test
Input
1
Output
1

1 Validator
Input
1
Output
1

2 Test
Input
2
Output
2

2 Validator
Input
2
Output
2

3 Test
Input
3
Output
4

3 Validator
Input
3
Output
4

10 Test
Input
10
Output
17

12 Validator
Input
12
Output
7

7888 Test
Input
7888
Output
12

7889 Validator
Input
7889
Output
26

99999 Test
Input
99999
Output
14

9999911 Validator
Input
9999911
Output
34

6000000 Test
Input
6000000
Output
34

Big Number Validator
Input
1234567
Output
21

Solution language

Solution

Stub generator input