#C10936. Collatz Sequence Length

    ID: 40196 Type: Default 1000ms 256MiB

Collatz Sequence Length

Collatz Sequence Length

Given a positive integer nn, compute the length of the Collatz sequence starting from nn until it reaches 1. The Collatz sequence is defined as follows:

  1. If n=1n = 1, the sequence terminates.
  2. If nn is even, the next term is n2\frac{n}{2}.
  3. If nn is odd and n>1n > 1, the next term is 3n+13n + 1.

Use memoization to optimize the computation for large values of nn. Your program should read a single integer from standard input and output the length of the sequence to standard output.

inputFormat

A single positive integer nn provided via standard input.

outputFormat

Output the number of terms in the Collatz sequence starting from nn until it reaches 1, printed to standard output.## sample

13
10

</p>