QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#549532 | #9167. Coprime Array | ucup-team3519# | TL | 164ms | 3692kb | C++23 | 1022b | 2024-09-06 17:07:31 | 2024-09-06 17:07:31 |
Judging History
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';
}
详细
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