QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549532#9167. Coprime Arrayucup-team3519#TL 164ms3692kbC++231022b2024-09-06 17:07:312024-09-06 17:07:31

Judging History

你现在查看的是最新测评结果

  • [2024-09-06 17:07:31]
  • 评测
  • 测评结果:TL
  • 用时:164ms
  • 内存:3692kb
  • [2024-09-06 17:07:31]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = int64_t;

std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
    i64 s, x;
    std::cin >> s >> x;

    if (std::gcd(s, x) == 1) {
        std::cout << "1\n";
        std::cout << s << '\n';
        return 0;
    }

    std::uniform_int_distribution<int> dist(0, x - 1);

    bool flag = false;
    auto get = [&](i64 s) {
        int T = 1e7;
        while (T--) {
            i64 a = dist(rng), b = s - a;
            if (llabs(std::gcd(a, x)) == 1 && llabs(std::gcd(b, x)) == 1) {
                flag = true;
                return std::make_pair(a, b);
            }
        }
        return std::make_pair(i64(0), i64(0));
    };

    auto [a, b] = get(s);
    if (flag) {
        std::cout << "2\n";
        std::cout << a << ' ' << b << '\n';
        return 0;
    }

    auto [p, q] = get(s + 1);
    assert(flag);
    std::cout << "3\n";
    std::cout << "-1 " << p << ' ' << q << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 164ms
memory: 3672kb

input:

9 6

output:

3
-1 5 5

result:

ok Correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

14 34

output:

2
15 -1

result:

ok Correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

1000000000 223092870

output:

2
59601341 940398659

result:

ok Correct

Test #4:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

2 1000000000

output:

2
387331729 -387331727

result:

ok Correct

Test #5:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

649557664 933437700

output:

2
176064833 473492831

result:

ok Correct

Test #6:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

33396678 777360870

output:

2
23319757 10076921

result:

ok Correct

Test #7:

score: -100
Time Limit Exceeded

input:

48205845 903124530

output:


result: