Pavel had two positive integers a and b. He found their sum s and greatest common divisor g, and forgot a and b after that. Help him to restore the original numbers.
Input
A single line contains two integers s and g (1 ≤ s ≤ 109, 1 ≤ g ≤ 109) — sum and greatest common divisor of the numbers a and b.
Output
If Pavel made a mistake and there are no such numbers a and b, output a single number - 1.
Otherwise, output two positive integers a and b on a single line, separated by a space. If there are multiple possible solutions, output any of them.
Examples
input
Copy
6 2
output
4 2
input
Copy
7 2
output
-1
题意:求两个数,已知他们的和以及他们的公约数
推导: 假设 两个数为 12 8 则和为20,公约数为4
12=3*4 8=2*4 3和2互质,所以最大公约数为1 故20=(3+2)*4 此时如果存在的话 那gcd(4,20-4)=gcd(4,4*4)的公约数肯定也为4,所以只需要判断gcd(s,g)==g?存在:不存在 如果存在
如果存在就把公约数作为一个数,因为此时其前面的系数为1,与其他数都互质
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int gcd(int x,int y)
{
return y==0?x:gcd(y,x%y);
}
int main()
{
int s,g;
while(~scanf("%d%d",&s,&g))
{
if(gcd(s-g,g)==g&&s!=g)
{
printf("%d %d\n",s-g,g);
}
else puts("-1");
}
return 0;
}