#P9849. Lock Box Ice Cream

    ID: 22994 Type: Default 1000ms 256MiB

Lock Box Ice Cream

Lock Box Ice Cream

In this problem, Chongyun is locked out of his ice cream by a strange lock invented by Xingqiu. The lock displays two integers \(a\) and \(b\). Chongyun can perform the following three operations any number of times:

  • Subtract \(1\) from both \(a\) and \(b\): \(a \rightarrow a-1,\; b \rightarrow b-1\).
  • Add \(1\) to both \(a\) and \(b\): \(a \rightarrow a+1,\; b \rightarrow b+1\).
  • Divide both \(a\) and \(b\) by one of their common prime factors. In other words, for any prime \(g\) such that \(g\) divides both \(a\) and \(b\), you can do: \(a \rightarrow \frac{a}{g},\; b \rightarrow \frac{b}{g}\).

The lock will be unlocked if at least one of \(a\) or \(b\) becomes exactly \(1\). Your task is to help Chongyun recover his ice cream by computing the minimum number of operations required to unlock the box.

inputFormat

The input consists of a single line containing two positive integers \(a\) and \(b\) separated by a space.

outputFormat

Output the minimum number of operations needed to unlock the box. If the box cannot be unlocked (which will not happen in the given test cases), output -1.

sample

2 2
1