The Collatz sequence is defined as follows for a positive integer n: - If n is even, divide it by 2. - If n is odd, multiply by 3 and add 1. The sequence terminates when it reaches 1. For example, starting with 13: 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1 (10 steps). Given N, find the starting number below N that produces the longest Collatz chain.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= N <= 10^6
Tags:
