QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#549534 | #9167. Coprime Array | ucup-team3519# | AC ✓ | 127ms | 3776kb | C++23 | 1022b | 2024-09-06 17:08:32 | 2024-09-06 17:08:32 |
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 = 1e6;
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';
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 17ms
memory: 3644kb
input:
9 6
output:
3 -1 5 5
result:
ok Correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
14 34
output:
2 9 5
result:
ok Correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
1000000000 223092870
output:
2 211041647 788958353
result:
ok Correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
2 1000000000
output:
2 506324399 -506324397
result:
ok Correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
649557664 933437700
output:
2 438633383 210924281
result:
ok Correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
33396678 777360870
output:
2 590841359 -557444681
result:
ok Correct
Test #7:
score: 0
Accepted
time: 118ms
memory: 3572kb
input:
48205845 903124530
output:
3 -1 736162289 -687956443
result:
ok Correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
251037078 505905400
output:
2 282128529 -31091451
result:
ok Correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
30022920 172746860
output:
2 86485653 -56462733
result:
ok Correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
63639298 808058790
output:
2 90626177 -26986879
result:
ok Correct
Test #11:
score: 0
Accepted
time: 112ms
memory: 3624kb
input:
76579017 362768406
output:
3 -1 11667203 64911815
result:
ok Correct
Test #12:
score: 0
Accepted
time: 127ms
memory: 3704kb
input:
40423669 121437778
output:
3 -1 73202025 -32778355
result:
ok Correct
Test #13:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
449277309 720915195
output:
2 166412248 282865061
result:
ok Correct
Test #14:
score: 0
Accepted
time: 125ms
memory: 3720kb
input:
81665969 919836918
output:
3 -1 489977021 -408311051
result:
ok Correct
Test #15:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
470578680 280387800
output:
2 24418039 446160641
result:
ok Correct
Test #16:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
58450340 803305503
output:
2 297716116 -239265776
result:
ok Correct
Test #17:
score: 0
Accepted
time: 112ms
memory: 3696kb
input:
125896113 323676210
output:
3 -1 317525477 -191629363
result:
ok Correct
Test #18:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
381905348 434752500
output:
2 142707769 239197579
result:
ok Correct
Test #19:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
78916498 653897673
output:
1 78916498
result:
ok Correct
Test #20:
score: 0
Accepted
time: 112ms
memory: 3584kb
input:
35787885 270845190
output:
3 -1 142085057 -106297171
result:
ok Correct
Extra Test:
score: 0
Extra Test Passed