#CCBOTPBA0000058. Truy vết Collatz độ dài (Collatz Sequence Length)
Truy vết Collatz độ dài (Collatz Sequence Length)
Collatz Sequence Length
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Start with a positive integer and record it as . While , replace by when it is even, or by when it is odd, and record the new value. Stop when 1 is reached. Count the number of recorded terms, including both the initial and the final 1. Do not print the sequence.
Input
One line contains one positive integer .
Output
Print one integer: the number of terms in the Collatz sequence from through 1.
Subtasks
- Subtask 1 (20%): .
- Subtask 2 (30%): .
- Subtask 3 (50%): .
Examples
Example 1
Input:
1
Output:
1
Explanation: The initial value already equals 1. No transformation occurs, but the sequence contains one term: 1.
Example 2
Input:
6
Output:
9
Explanation: The recorded terms are 6, 3, 10, 5, 16, 8, 4, 2, 1. There are eight transformations but nine terms.
Example 3
Input:
3
Output:
8
Explanation: The sequence is 3, 10, 5, 16, 8, 4, 2, 1, containing eight terms.