Three X Plus One
There exists a famous unsolved problem in mathematics called the Collatz Conjecture, that states the following:
Starting at a positive integer , a specific sequence will always reach
following these rules:
- If
is even, divide it by two.
- If
is odd, it becomes
.
For all positive integers below or equal to a number , you are interested in finding the number which takes the most steps to reach 1.
Input
The input consists of a single integer input
.
Output
Output a single integer, the starting number which results in the most steps to reach 1. If there are multiple integers which result in the most steps, output the largest one.
Example
Input
5
Output
3
Starting at , we take
steps to reach
.
is odd,
.
is even,
.
is odd,
.
is even,
.
is even,
.
is even,
.
is even,
.
It can be proven that there is no number less than or equal to that takes more steps to reach
.
Example 2
Input
1
Output
1
There is only one number to test — 1, which since is already at 1, takes 0 steps.
Comments