UVa11388(gcd+水题)

题意

给连个数G,L,求出另外两个数a,b,使得gcd(a,b)=G,lcm(a,b)=L,如果有多种情况,输出a最小的情况

分析

简单分析一下可以得到gcd(G,L)=G,lcm(G,L)=L,那么会不会有其他的a比G更小呢,显然不会。因为G是a和其他数的最大公因数,只可能是G<=a.所以最后判断一下G能否整除L即可,不能则输出-1,否则输出G,L.

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(false);
    int l, g, t;
    cin >> t;
    while (t--)
    {
        cin >> g >> l;
        if (l%g == 0) cout << g << " " << l << endl;
        else cout << -1 << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/cugsl/article/details/81747357
今日推荐