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 = 3e3 + 10;
const ll oo = 1e10;
int gcd[N][N], val[N][N];
int f(int x, int y)
{
if (y > x) swap(x, y);
if (val[x][y] != 0) return val[x][y];
if (y == 1) return val[x][y] = x;
else return val[x][y] = f(x / y, y);
}
int gd(int x, int y)
{
if (x < y) swap(x, y);
if (y == 0) return x;
if (gcd[x][y] != 0) return gcd[x][y];
return val[x][y] = gd(x % y, y);
}
int main()
{
int t;
cin >> t;
for (int i = 1; i < N; i++)
for (int j = 1; j < N; j++) gcd[i][j] = gd(i, j), val[i][j] = f(i, j);
while (t--)
{
int x, y;
cin >> x >> y;
int l = -1, r = -1;
for (int i = 1; i <= 1000; i++)
for (int j = 1; j <= 1000; j++)
if (gcd[i][j] == x && val[i][j] == y) l = i, r = j;
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... |