题意:给你两个数G和L,输出两个正整数,最大公约数为G,最小公倍数为L,输出a最小的情况,如果不存在输出-1。
思路:当a最小时,a = G,所以只要L % G == 0,就表示存在。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int g, l;
int main() {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%d%d", &g, &l);
if (g > l) {
swap(g, l);
}
if (l % g == 0)
printf("%d %d\n", g, l);
else
printf("-1\n");
}
return 0;
}