Reduce N To 1

easy
1. You are given a positive number N.
2. You have to find the minimum number of operations required to convert N into 1.
3. Operations allowed :
     (i)  If n is even, you have to replace n with n/2.
     (ii) If n is odd, you can replace n with either n-1 or n+1.

Input Format

A number N

Output Format

Check the sample ouput and question video.

Constraints

1 <= N <= 2147483647

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
8
Output
3
Previous
Triplets - 1
Next
Pepcoder And Bits

Related Questions