讲道理,学 c 语言的时候肯定学过 求 GCD 和 LCM,
一般是求出 a, b 的GCD后, LCM = a * b / GCD ;
这样就ok了, (LCM / GCD) = ( a / GCD ) * ( b / GCD );
而且 ( a / GCD ) 和 ( b / GCD ) 互质
** 额,,我在输入 G 和 L 是忘记判断合法性,错了,也就是 样例2,,,2333
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<algorithm>
// cout << " === " << endl;
using namespace std;
typedef long long ll;
const int maxn = 1000000 + 7, INF = 0x3f3f3f3f, mod = 1e9+7;
int T;
ll G, L;
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int main () {
scanf("%d", &T);
while(T--) {
scanf("%lld%lld", &G, &L);
if( (L/G) * G != L) { cout << -1 << endl; continue; }
else L /= G;
int f = 0;
for(ll i = 1; i * i <= L; ++i) {
ll t = L / i;
if(i*t == L && gcd(i, t) == 1 ) {
f = 1;
cout << i*G << " " << t*G << endl;
break;
}
}
if(!f) cout << -1 << endl;
}
return 0;
}