I’m not sure what you’re asking for.
Given two positive integers A and B given. We can easily find the greatest common divisor G and the least common multiple L of two numbers A and B.
Now let’s consider the inverse of the above problem:
Given in advance the greatest common divisor G and the least common multiple L of two positive integers A and B.
Obviously, there will be many pairs of (A, B) positive integers whose greatest common divisor is G and least common multiple is L, but there are also cases where we cannot find a satisfactory value of A and B. Determine the minimum value of the sum A + B, or give -1 if the pair (A, B) cannot be found”.
Input
Two positive integers G and L (1 = G = L = 10^9).
Output
A positive integer is the smallest possible sum. In case two numbers A and B cannot be found, the result is -1.
Google is your friend.