Submission #374454

# Submission time Handle Problem Language Result Execution time Memory
374454 2021-03-07T09:59:12 Z Vimmer Euklid (COCI20_euklid) C++14
20 / 110
180 ms 768 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

#define N 1005
#define NN 1005000
#define PB push_back
#define M ll(1e9 + 7)
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define pri(x) cout << x << endl
#define endl '\n'
#define _ << " " <<
#define F first
#define S second

using namespace std;
//using namespace __gnu_pbds;

//typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> oredered_set;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef short int si;

int brd(int a, int b)
{
    if (b > a)
        swap(a, b);

    if (b == 1)
        return a;

    return brd(a / b, b);
}

int gc(int a, int b)
{
    if (a > b)
        swap(a, b);

    if (a == 0)
        return b;

    return gc(b, b % a);
}

pair <int, int> pt[210][210];

pair <int, int> fnd(int gc, int x)
{
    int p = (x + x) / gc;

    int r = p * gc;

    if (r == x + x)
        r -= gc;

    p = x / gc;

    int l = p * gc;

    if (l != x)
        l += gc;

    for (int y = l; y <= r; y += gc)
            {
                if (__gcd(y, x) == gc) return {y, x};

                for (int t = x * y; t < (x + 1) * y; t++)
                    if (__gcd(y, t) == gc)
                        return {y, t};
            }

    for (int y = x; y < x + x; y++)
    {
        if (y % gc == 0) continue;

        r = (y * (x + 1));

        r /= gc;

        r *= gc;

        if (r == (y * (x + 1)))
            r -= gc;

        l = (y * x) / gc;

        l *= gc;

        if (l != y * x)
            l += gc;

        for (int nx = l; nx <= r; nx += gc)
        {
            for (int t = nx * y; t < nx * (y + 1); t++)
                if (__gcd(t, nx) == gc)
                    return {nx, t};
        }
    }

    return {0, 0};
}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("1.in", "r", stdin);

    for (int i = 1; i <= 200; i++)
        for (int j = 2; j <= 200; j++)
        {
            pt[i][j] = fnd(i, j);
        }

    for (int i = 2; i <= 1000; i++)
        for (int j = 2; j <= 1000; j++)
        {
            int gc = __gcd(i, j);

            int bd = brd(i, j);

            if (gc > 200 || bd > 200) continue;

            if (pt[gc][bd].F != 0) continue;

            pt[gc][bd] = {i, j};
        }

//    int kol = 0;
//
//    for (int i = 1; i <= 200; i++)
//        for (int j = 2; j <= 200; j++)
//            if (pt[i][j].F == 0)
//                {
//                    kol++;
//                }

//    pri(kol);

    int q;

    cin >> q;

    for (; q > 0; q--)
    {
        ll gc, bd;

        cin >> gc >> bd;

        if (gc == bd)
        {
            pri(gc _ bd);

            continue;
        }

        if (bd == 2)
        {
            pri(gc + gc _ gc);

            continue;
        }

        if (gc == bd && bd == 1)
        {
            pri(3 _ 2);

            continue;
        }

        if (bd * bd == gc)
        {
            pri(gc _ bd * gc);

            continue;
        }

        if (pt[gc][bd].F != 0)
            pri(pt[gc][bd].F _ pt[gc][bd].S);
        {
            pair <int, int> pt = fnd(gc, bd);

            if (pt.F == 0)
                assert(0);

            pri(pt.F _ pt.S);
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 150 ms 628 KB Output is correct
2 Correct 148 ms 620 KB Output is correct
3 Correct 150 ms 620 KB Output is correct
4 Correct 151 ms 748 KB Output is correct
5 Correct 155 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 620 KB Output is correct
2 Correct 149 ms 620 KB Output is correct
3 Correct 148 ms 620 KB Output is correct
4 Correct 148 ms 620 KB Output is correct
5 Correct 151 ms 620 KB Output is correct
6 Correct 155 ms 620 KB Output is correct
7 Correct 150 ms 620 KB Output is correct
8 Correct 148 ms 620 KB Output is correct
9 Correct 149 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 748 KB Output is correct
2 Correct 168 ms 620 KB Output is correct
3 Correct 180 ms 620 KB Output is correct
4 Correct 171 ms 768 KB Output is correct
5 Correct 159 ms 620 KB Output is correct
6 Correct 180 ms 620 KB Output is correct
7 Correct 153 ms 620 KB Output is correct
8 Correct 174 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 149 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 149 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 150 ms 628 KB Output is correct
2 Correct 148 ms 620 KB Output is correct
3 Correct 150 ms 620 KB Output is correct
4 Correct 151 ms 748 KB Output is correct
5 Correct 155 ms 768 KB Output is correct
6 Correct 154 ms 620 KB Output is correct
7 Correct 149 ms 620 KB Output is correct
8 Correct 148 ms 620 KB Output is correct
9 Correct 148 ms 620 KB Output is correct
10 Correct 151 ms 620 KB Output is correct
11 Correct 155 ms 620 KB Output is correct
12 Correct 150 ms 620 KB Output is correct
13 Correct 148 ms 620 KB Output is correct
14 Correct 149 ms 748 KB Output is correct
15 Correct 148 ms 748 KB Output is correct
16 Correct 168 ms 620 KB Output is correct
17 Correct 180 ms 620 KB Output is correct
18 Correct 171 ms 768 KB Output is correct
19 Correct 159 ms 620 KB Output is correct
20 Correct 180 ms 620 KB Output is correct
21 Correct 153 ms 620 KB Output is correct
22 Correct 174 ms 748 KB Output is correct
23 Incorrect 149 ms 620 KB Output isn't correct
24 Halted 0 ms 0 KB -