#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9+7;
const int inf = 1e18 + 10;
const int L = 20 * 20 * 20;
int gcd(int a, int b){
if(a < b) swap(a, b);
if(b == 0) return a;
return gcd(b, a%b);
}
int r(int a, int b){
if(a < b) swap(a, b);
if(b == 1) return a;
return r(a/b, b);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--){
int g, h;
cin>>g>>h;
if(g == h){
cout<<g<<" "<<g<<endl;
continue;
}
int a = g * (h/g + (h%g ? 1 : 0));
int b = -1;
for(int i = g; i <= N; i += g){
if(gcd(i, a) == g && r(i, a) == h){
b = i;
break;
}
}
cout<<a<<" "<<b<<endl;
//if(b == -1) cout<<"ah be"<<endl;
//else if(gcd(a, b) == g && r(a, b) == h) cout<<1<<endl;
//else cout<<0<<endl;
/*
for(int i = g; i <= 200; i += g){
for(int j = i; j <= 200; j += g){
if(gcd(i, j) == g && r(i, j) == h){
cout<<i<<" "<<j<<endl;
}
}
}
*/
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Integer parameter [name=b] equals to -1, violates the range [1, 10^18] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Integer parameter [name=b] equals to -1, violates the range [1, 10^18] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
2 ms |
348 KB |
Integer parameter [name=b] equals to -1, violates the range [1, 10^18] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
2 ms |
348 KB |
Integer parameter [name=b] equals to -1, violates the range [1, 10^18] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Integer parameter [name=b] equals to -1, violates the range [1, 10^18] |
9 |
Halted |
0 ms |
0 KB |
- |