Problems > Collatz Peak

Collatz Peak

Difficulty: 1000 2000 ms 128 MB

math implementation

Following the same Collatz process to 1, print the LARGEST value the sequence ever reaches (including N itself).

Input: one integer N.

Output: the maximum value on the trajectory.

Constraints:

  • 1 ≤ N ≤ 106

Sample Tests

Input 1
7
Output 1
52
Input 2
1
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.