#C5232. Longest Collatz Sequence

    ID: 48859 Type: Default 1000ms 256MiB

Longest Collatz Sequence

Longest Collatz Sequence

The Collatz conjecture is one of the most famous unsolved problems in mathematics. For any positive integer \( n \), the Collatz sequence is defined as follows:

  • If \( n = 1 \), the sequence ends.
  • If \( n \) is even, then the next term is \( n/2 \) (i.e. \( n_{k+1} = \frac{n_k}{2} \)).
  • If \( n \) is odd, then the next term is \( 3n+1 \) (i.e. \( n_{k+1} = 3n_k+1 \)).

The length of the Collatz sequence is the number of terms from the initial number \( n \) until 1 is reached. Given two numbers \( L \) and \( R \), your task is to compute the maximum length among all Collatz sequences for numbers in the range [\( L, R \)].

For example, when \( L = 1 \) and \( R = 10 \), the maximum sequence length is 20.

inputFormat

Input is provided via standard input (stdin) and consists of two space-separated integers \( L \) and \( R \) where \( L \le R \). These represent the range for which you need to determine the maximum Collatz sequence length.

outputFormat

Output the maximum Collatz sequence length, printed to standard output (stdout).

## sample
1 10
20