GCD 与 LCM UVA - 11388

题目链接:

https://cn.vjudge.net/problem/23709/origin

本题其实有坑

数据大小太大, 2的32次方,故而一定是取巧的算法,暴力不可能过的

思路是最大公因数的倍数是最小公倍数,又有a <= b所以可以知道 a = gcd, b = lcm

AC代码如下:

#include <cstdio>
#define ll long long

using namespace std;

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        ll x, y;
        scanf("%lld%lld", &x, &y);
        if(y%x != 0)
        {
            printf("-1\n");
            continue;
        }
        printf("%lld %lld\n", x, y);
    }
}
View Code

如有疑问,欢迎评论指出!

 

posted @ 2019-01-19 16:37  mpeter  阅读(90)  评论(0编辑  收藏  举报