eolymp
bolt
Try our new interface for solving problems
Problems

Decreasing Number

Decreasing Number

There are three types of operations that can be performed on an integer: \begin{itemize} \item If the number is divisible by $3$, divide it by $3$; \item If the number is divisible by $2$, divide it by $2$; \item Subtract $1$. \end{itemize} For a given positive integer $n$, find the minimum number of operations required to obtain $1$. \InputFile Each line contains a single positive integer $n~(1 \le n \le 10^6)$. \OutputFile For each value of $n$, print the minimum number of operations required to obtain $1$ on a separate line.
Time limit 1 second
Memory limit 128 MiB
Input example #1
1
5
10
Output example #1
0
3
3