Problem list
Log in
#r03331 · Online Judge > GoldOJ

Make It One

Silver III 2.0 s 256 MB

Starting from $N$, you may repeatedly (a) divide by $3$ if divisible, (b) divide by $2$ if divisible, or (c) subtract $1$. Print the minimum number of operations to reach $1$.

Input

One integer $N$ ($1 \le N \le 10^6$).

Output

Print the minimum number of operations.

Example 1

Input
2
Output
1

Example 2

Input
10
Output
3
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code