#K291. Collatz Sequence Analysis
Collatz Sequence Analysis
Collatz Sequence Analysis
Given a positive integer (N), generate its Collatz sequence (also known as the 3n+1 sequence) and determine two values: the maximum number encountered in the sequence and the length of the sequence. The Collatz sequence is defined as follows:
- Start with (N).
- If (N = 1), the sequence terminates.
- If (N) is even, the next number is (N/2).
- If (N) is odd, the next number is (3N+1).
For example, if (N = 7), the sequence is: 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1. The maximum number in this sequence is 52 and the total length is 17.
Your task is to read an integer from standard input, compute these two values, and print them separated by a space.
inputFormat
Input is given via standard input. It consists of a single integer (N) (where (N \geq 1)).
outputFormat
Output two space-separated integers: the maximum number encountered in the Collatz sequence starting from (N), and the length of the sequence.## sample
7
52 17