#C8145. Collatz Conjecture Analysis
Collatz Conjecture Analysis
Collatz Conjecture Analysis
Given a positive integer \( n \), perform an analysis on its Collatz sequence. The Collatz sequence is defined by the following recurrence relation:
\( n_{next} = \begin{cases}\frac{n}{2} &\text{if } n \text{ is even} \\ 3n+1 &\text{if } n \text{ is odd}\end{cases}\)
Your task is to compute the following:
- The number of steps required for \( n \) to reach 1.
- The maximum value encountered in the sequence.
- The full Collatz sequence starting from \( n \) and ending at 1.
Note: The step count does not include the starting number \( n \) but counts each transition until 1 is reached.
inputFormat
A single positive integer ( n ) provided in one line from standard input.
outputFormat
Print three lines to standard output:
- The first line contains the number of steps required for ( n ) to reach 1.
- The second line contains the maximum value encountered in the sequence.
- The third line contains the full Collatz sequence as space-separated integers.## sample
13
9
40
13 40 20 10 5 16 8 4 2 1
</p>