This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 7;
int g,h;
inline int gcd(int a, int b){
if(a > b)return gcd(b,a);
else if(a == 0)return b;
else return gcd(b%a,a);
}
inline int R(int a, int b){
if(a < b)return R(b,a);
else if(a >= b and b > 1)return R(a/b,b);
else return a;
}
inline int closest(int ql , int qr , int qj){
//cout << "bs : " << ql << " " << qr << " " << qj << endl;
int l = ql , r = qr;
while(l < r){
int mid = (l+r)/2;
if(R(mid*g , qj/mid) >= h)r = mid;
else l = mid+1;
}
//cout << "done" << endl;
return l;
}
void solve(){
cin >> g >> h;
for(int j = 1;j<=N;j++){
int l = j/2+1 , r = j , cur = 1;
while(true){
int temp = closest(l,r,j);
//cout << "temp : " << temp << endl;
if(R(temp*g , j/temp) == h){
cout << temp*g << " " << j*g << endl;
return;
}
r = l-1;
if(r == 0)break;
cur = j/r;
l = j/(cur+1) + 1;
}
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int testcase = 1;cin >> testcase;
while(testcase--)solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |