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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值