eolymp
bolt
Try our new interface for solving problems
Problems

Divisor Increase

Divisor Increase

There is an integer $k$. You are allowed to add to $k$ any of its divisors not equal to $1$ and $k$. The same operation can be applied to the resulting number and so on. Notice that starting from the number $4$, we can reach any composite number by applying several such operations. For example, the number $24$ can be reached starting from $4$ using $5$ operations: $4 \rightarrow 6 \rightarrow 8 \rightarrow 12 \rightarrow 18 \rightarrow 24$. You have to solve a more general problem. Find the minimal number of the described operations necessary to transform $n$ into $m$. \InputFile Each line contains two integers $n$ and $m\:(4 \le n \le m \le 10^5)$. \OutputFile For each test case, print in a separate line the minimal number of operations to transform $n$ into $m$. Print $-1$ if $m$ can't be obtained from $n$.
Time limit 1 second
Memory limit 128 MiB
Input example #1
4 24
4 576
8748 83462
Output example #1
5
14
10