#include<bits/stdc++.h>
#define iter(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define lsort(a) sort(iter(a))
#define eb emplace_back
#define gsort(a) sort(iter(a), greater<>());
using namespace std;
typedef long long ll;
ll R(ll a, ll b){
while(b > 1){
if(a < b) swap(a, b);
a /= b;
//cerr << a << " " << b << "\n";
}
return a;
}
vector<ll> lpd, prime;
void sieve(int n){
lpd.resize(n + 1, 1);
for(int i = 2; i <= n; i++){
if(lpd[i] == 1){
prime.eb(i);
lpd[i] = i;
}
for(ll j : prime){
if(i * j > n) break;
lpd[i * j] = j;
if(j == lpd[i]) break;
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
sieve(1000000);
int T;
cin >> T;
while(T--){
ll g, h;
cin >> g >> h;
ll a = -1, b = -1;
if(g == h){
a = b = g;
}
else if(h == 2){
a = g * 2;
b = g;
}
else if(g == h * h){
a = g * h;
b = g;
}
else{
for(ll i = 1; i <= 5000; i++){
for(ll j = 1; j <= 5000; j++){
if(__gcd(i, j) == 1 && R(g * i, g * j) == h){
a = g * i, b = g * j;
goto ok;
}
}
}
}
ok:;
//assert(__gcd(a, b) == g && R(a, b) == h);
cout << a << " " << b << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
9324 KB |
Output is correct |
2 |
Correct |
15 ms |
9324 KB |
Output is correct |
3 |
Correct |
15 ms |
9324 KB |
Output is correct |
4 |
Correct |
15 ms |
9324 KB |
Output is correct |
5 |
Correct |
18 ms |
9324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
9324 KB |
Output is correct |
2 |
Correct |
16 ms |
9324 KB |
Output is correct |
3 |
Correct |
15 ms |
9324 KB |
Output is correct |
4 |
Correct |
15 ms |
9324 KB |
Output is correct |
5 |
Correct |
15 ms |
9324 KB |
Output is correct |
6 |
Correct |
15 ms |
9324 KB |
Output is correct |
7 |
Correct |
15 ms |
9324 KB |
Output is correct |
8 |
Correct |
15 ms |
9324 KB |
Output is correct |
9 |
Correct |
15 ms |
9368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
9324 KB |
Output is correct |
2 |
Correct |
15 ms |
9324 KB |
Output is correct |
3 |
Correct |
16 ms |
9456 KB |
Output is correct |
4 |
Correct |
15 ms |
9324 KB |
Output is correct |
5 |
Correct |
15 ms |
9324 KB |
Output is correct |
6 |
Correct |
16 ms |
9324 KB |
Output is correct |
7 |
Correct |
17 ms |
9324 KB |
Output is correct |
8 |
Correct |
14 ms |
9324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
9324 KB |
Output is correct |
2 |
Correct |
42 ms |
9324 KB |
Output is correct |
3 |
Correct |
28 ms |
9324 KB |
Output is correct |
4 |
Correct |
24 ms |
9324 KB |
Output is correct |
5 |
Correct |
22 ms |
9324 KB |
Output is correct |
6 |
Correct |
20 ms |
9324 KB |
Output is correct |
7 |
Correct |
21 ms |
9324 KB |
Output is correct |
8 |
Correct |
21 ms |
9324 KB |
Output is correct |
9 |
Correct |
23 ms |
9324 KB |
Output is correct |
10 |
Correct |
22 ms |
9324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
9324 KB |
Output is correct |
2 |
Correct |
42 ms |
9324 KB |
Output is correct |
3 |
Correct |
28 ms |
9324 KB |
Output is correct |
4 |
Correct |
24 ms |
9324 KB |
Output is correct |
5 |
Correct |
22 ms |
9324 KB |
Output is correct |
6 |
Correct |
20 ms |
9324 KB |
Output is correct |
7 |
Correct |
21 ms |
9324 KB |
Output is correct |
8 |
Correct |
21 ms |
9324 KB |
Output is correct |
9 |
Correct |
23 ms |
9324 KB |
Output is correct |
10 |
Correct |
22 ms |
9324 KB |
Output is correct |
11 |
Correct |
23 ms |
9324 KB |
Output is correct |
12 |
Execution timed out |
1085 ms |
9324 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
9324 KB |
Output is correct |
2 |
Correct |
15 ms |
9324 KB |
Output is correct |
3 |
Correct |
15 ms |
9324 KB |
Output is correct |
4 |
Correct |
15 ms |
9324 KB |
Output is correct |
5 |
Correct |
18 ms |
9324 KB |
Output is correct |
6 |
Correct |
15 ms |
9324 KB |
Output is correct |
7 |
Correct |
16 ms |
9324 KB |
Output is correct |
8 |
Correct |
15 ms |
9324 KB |
Output is correct |
9 |
Correct |
15 ms |
9324 KB |
Output is correct |
10 |
Correct |
15 ms |
9324 KB |
Output is correct |
11 |
Correct |
15 ms |
9324 KB |
Output is correct |
12 |
Correct |
15 ms |
9324 KB |
Output is correct |
13 |
Correct |
15 ms |
9324 KB |
Output is correct |
14 |
Correct |
15 ms |
9368 KB |
Output is correct |
15 |
Correct |
17 ms |
9324 KB |
Output is correct |
16 |
Correct |
15 ms |
9324 KB |
Output is correct |
17 |
Correct |
16 ms |
9456 KB |
Output is correct |
18 |
Correct |
15 ms |
9324 KB |
Output is correct |
19 |
Correct |
15 ms |
9324 KB |
Output is correct |
20 |
Correct |
16 ms |
9324 KB |
Output is correct |
21 |
Correct |
17 ms |
9324 KB |
Output is correct |
22 |
Correct |
14 ms |
9324 KB |
Output is correct |
23 |
Correct |
37 ms |
9324 KB |
Output is correct |
24 |
Correct |
42 ms |
9324 KB |
Output is correct |
25 |
Correct |
28 ms |
9324 KB |
Output is correct |
26 |
Correct |
24 ms |
9324 KB |
Output is correct |
27 |
Correct |
22 ms |
9324 KB |
Output is correct |
28 |
Correct |
20 ms |
9324 KB |
Output is correct |
29 |
Correct |
21 ms |
9324 KB |
Output is correct |
30 |
Correct |
21 ms |
9324 KB |
Output is correct |
31 |
Correct |
23 ms |
9324 KB |
Output is correct |
32 |
Correct |
22 ms |
9324 KB |
Output is correct |
33 |
Correct |
23 ms |
9324 KB |
Output is correct |
34 |
Execution timed out |
1085 ms |
9324 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |