UVA11388 GCD LCM1 2 -1

题目:

  给你两个数G和L,求a和b,他们的最大公约数为G和最小公倍数为L,输出a最小时的a和b。如果不存在在输出-1.

Sample Input

 

2

1 2

3 4

Output for Sample Input

1 2

-1

 

分析:

  其实很简单,想到思路就好了,a最小时其实就是G,对应的b必然为L,当L不是G的倍数是不存在a和b

代码:

  

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int l,r,n;
    cin>>n;
    int i;
    for(i=0;i<n;i++)
    {
        cin>>l>>r;
        if(r%l!=0)
            cout<<-1<<endl;
        else
            cout<<l<<" "<<r<<endl;
    }
}
posted @ 2015-07-28 16:52  幻世沉溺  阅读(160)  评论(0编辑  收藏  举报