#P11130. Transforming Integer via GCD Multiplication

    ID: 13191 Type: Default 1000ms 256MiB

Transforming Integer via GCD Multiplication

Transforming Integer via GCD Multiplication

You are given two positive integers n and m. You have an integer x which is initially equal to n. You can perform the following operation any number of times (including zero):

Choose a positive integer y and update x to
[ x \gets x \times \gcd(x, y), ]
where (\gcd(x, y)) denotes the greatest common divisor of x and y.

Your task is to determine the minimum number of operations required to transform n into m, or to report that it is impossible. Note that if no operation is needed, the answer is 0.

inputFormat

The input consists of a single line containing two space-separated positive integers n and m.

outputFormat

Output a single integer representing the minimum number of operations required to transform n into m. If it is impossible, output -1.

sample

4 8
1