Longest Collatz chain
Statement
The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined as follows:
Collatz(n) = {
stop if n is 1
if n is even, return n / 2
if n is odd, return 3*n + 1
}
The conjecture is that no matter what value of n, the sequence will always reach 1.
The task is to find the number producing the longest sequence up to a given limit and the length of the sequence.
The numbers in the sequence might go well over the given limit before they finally reach 1!
Input description
<<Line 1:>> An integer [[limit]] for the upper limit of the search
Output description
<<Line 1:>> Two space-separated integers [[number]] for the number producing the longest chain and [[length]] for the length of that chain.
Constraints
1 ≤ [[limit]], [[number]] ≤ 1000000
1 ≤ [[length]] ≤ 1000
Game modes
Shortest
Test cases
Test 1 Test
Input
20
Output
18 21
Validator 1 Validator
Input
10
Output
9 20
Test 2 Test
Input
100
Output
97 119
Validator 2 Validator
Input
90
Output
73 116
Test 3 Test
Input
1000
Output
871 179
Validator 3 Validator
Input
870
Output
703 171
Test 4 Test
Input
11000
Output
10971 268
Validator 4 Validator
Input
10000
Output
6171 262
Test 5 Test
Input
110000
Output
106239 354
Validator 5 Validator
Input
100000
Output
77031 351
Test 6 Test
Input
500000
Output
410011 449
Validator 6 Validator
Input
410000
Output
230631 443
Test 7 Test
Input
1000000
Output
837799 525
Validator 7 Validator
Input
830000
Output
626331 509
Solution language
Solution
Stub generator input