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>
#define f first
#define s second
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const ll N = 2e3 + 100;
ll gcd[N][N];
ll f(ll x, ll y)
{
if (x < y) swap(x, y);
if (y == 1) return x;
else return f(x / y, y);
}
int main()
{
for (ll i = 1; i < N; i++)
for (ll j = 1; j < N; j++) gcd[i][j] = __gcd(i, j);
ll t;
cin >> t;
while (t--)
{
ll x, y;
cin >> x >> y;
if (x == y)
{
cout << x << " " << x << endl;
continue;
}
if (y == 2)
{
cout << x << " " << 2 * x << endl;
continue;
}
if (x == y * y)
{
cout << x << " " << x * y << endl;
continue;
}
ll l = -1, r = -1;
for (ll i = 1; i < N; i++)
for (ll j = 1; j < N; j++)
if (gcd[i][j] == 1 && f(i * x, j * x) == y) {l = i * x, r = j * x;break;}
cout << l << " " << r << endl;
}
}
# | 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... |