Restoring Number【找规律,有坑】

Discription
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
6 2
Output
4 2

Input
7 2
Output
-1

题意
Pavel有两个正整数a和b。 他找到了它们的和s和最大公约数g,然后忘记了a和b。 帮助他恢复原始数字。
输入包含两个整数s和g(1≤s≤109,1≤g≤109),表示a和b的和和最大公约数。

思路
思路很简单。
首先判断s能不能整除g,不能就直接不符合条件。再就是可能了我很久的一条就是,s和g要满足的条件是s<g。
然后用g做其中一个属,那s-g就是另一个数。

AC代码

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;

ll q,n;

int main()
{
    scanf("%lld %lld",&q,&n);
    if(q<=n||q%n!=0)
    {
        printf("-1\n");
        return 0;
    }
    printf("%lld %lld\n",n,q-n);
    return 0;
}
发布了306 篇原创文章 · 获赞 105 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43460224/article/details/104110595