題目:
給你兩個數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; }}
新聞熱點
疑難解答