cho.sh
Notes
Loading...

Minimum Power Operations

Time limit

2s

Memory limit

128 MB

Problem

We want to compute x^P using as few operations as possible, where 1 <= P <= 20,000. During the computation, only two variables may be used.

Initially, one variable stores x and the other stores 1. In one operation, choose two values currently stored in the variables, multiply them or divide one by the other, and store the result in either variable. The same variable may be chosen twice, so squaring a stored value is allowed. The final result may be stored in either variable.

For example, x^9 can be computed in 4 operations as follows.

Number of operations01234
Variable 1xxxx^5x^9
Variable 21x^2x^4x^4x^4

Given P, find the minimum number of operations required to compute x^P.

Input

The first line contains P.

Output

Print the minimum number of operations.