Submission #374497

#TimeUsernameProblemLanguageResultExecution timeMemory
374497topovikEuklid (COCI20_euklid)C++14
20 / 110
2 ms748 KiB
#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 int N = 1e2 + 100;

int gcd[N][N];

int f(int x, int y)
{
    if (x < y) swap(x, y);
    if (y == 1) return x;
    else return f(x / y, y);
}

int main()
{
    for (int i = 1; i < N; i++)
        for (int j = 1; j < N; j++) gcd[i][j] = __gcd(i, j);
    int 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;
        }
        int l = -1, r = -1;
        for (int i = 1; i < N; i++)
            for (int j = 1; j < N; j++)
              if (gcd[i][j] == 1 && f(i / j, j * x) == y) {l = i, r = j;break;}
        cout << l << " " << r << endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...