#C10936. Collatz Sequence Length
Collatz Sequence Length
Collatz Sequence Length
Given a positive integer , compute the length of the Collatz sequence starting from until it reaches 1. The Collatz sequence is defined as follows:
- If , the sequence terminates.
- If is even, the next term is .
- If is odd and , the next term is .
Use memoization to optimize the computation for large values of . 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 provided via standard input.
outputFormat
Output the number of terms in the Collatz sequence starting from until it reaches 1, printed to standard output.## sample
13
10
</p>