#C4385. Sequence Length
Sequence Length
Sequence Length
Given an integer x
, compute the length of the sequence formed by the following iterative process: if x
is even, then replace it with \( \frac{x}{2} \); if x
is odd, then replace it with \( 3x+1 \). The process terminates when x
becomes 1. The length of the sequence is defined as the number of terms, including the initial x
and the terminal 1.
Example:
- For
x = 6
: The sequence is 6, 3, 10, 5, 16, 8, 4, 2, 1, so the length is 9.
Your task is to implement a solution that reads the integer from standard input and prints the length of the sequence to standard output.
inputFormat
The input consists of a single integer x
(\( x \ge 1 \)).
This integer is provided via stdin.
outputFormat
Output a single integer representing the length of the sequence on stdout.
## sample6
9