QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#512141 | #9167. Coprime Array | ucup-team3699# | AC ✓ | 139ms | 3836kb | C++20 | 1.6kb | 2024-08-10 13:39:31 | 2024-08-10 13:39:33 |
Judging History
answer
#include<iostream>
#include<vector>
#include<algorithm>
#include<random>
#include<set>
#include<assert.h>
using namespace std;
#define int long long
#define N 1000005
#define pii pair<int, int>
#define F first
#define S second
#define MX (int)(5e8)
int gcd(int a, int b){
return (b == 0 ? a : gcd(b, a % b));
}
random_device rd;
mt19937 rng(rd());
int s, x;
void solve(){
cin >> s >> x;
if(gcd(s, x) == 1){
cout << "1\n";
cout << s << "\n";
return;
}
int mi3 = 0;
int add = 0;
set<int> st;
for (int i = 0; i < N; i++){
int now = rng() % MX;
if(st.count(now) || gcd(x, now) > 1)
continue;
if(gcd(abs(s - now), x) == 1){
cout << "2\n";
cout << now << " " << s - now << "\n";
return;
}
if(!add){
if(gcd(abs(s - now - 1), x) == 1){
mi3 = now;
add = 1;
}
if(gcd(abs(s - now + 1), x) == 1){
mi3 = now;
add = -1;
}
}
}
if(!add){
cout << s << " " << x << "\n";
exit(0);
}
cout << "3\n";
cout << add << " " << mi3 << " " << s - add - mi3 << "\n";
}
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
solve();
return 0;
}
// signed main(){
// ios_base::sync_with_stdio(0), cin.tie(0);
// x = 203693490;
// for (int t = 0; t <= 1000; t++)
// s = rng(), solve();
// return 0;
// }
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 26ms
memory: 3604kb
input:
9 6
output:
3 -1 423784355 -423784345
result:
ok Correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
14 34
output:
2 472309241 -472309227
result:
ok Correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
1000000000 223092870
output:
2 347758391 652241609
result:
ok Correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
2 1000000000
output:
2 25915101 -25915099
result:
ok Correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
649557664 933437700
output:
2 2785667 646771997
result:
ok Correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
33396678 777360870
output:
2 394068127 -360671449
result:
ok Correct
Test #7:
score: 0
Accepted
time: 118ms
memory: 3836kb
input:
48205845 903124530
output:
3 -1 482979989 -434774143
result:
ok Correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
251037078 505905400
output:
2 277641379 -26604301
result:
ok Correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
30022920 172746860
output:
2 67534527 -37511607
result:
ok Correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
63639298 808058790
output:
2 238866671 -175227373
result:
ok Correct
Test #11:
score: 0
Accepted
time: 119ms
memory: 3536kb
input:
76579017 362768406
output:
3 -1 494942333 -418363315
result:
ok Correct
Test #12:
score: 0
Accepted
time: 139ms
memory: 3600kb
input:
40423669 121437778
output:
3 -1 24820959 15602711
result:
ok Correct
Test #13:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
449277309 720915195
output:
2 78008057 371269252
result:
ok Correct
Test #14:
score: 0
Accepted
time: 117ms
memory: 3540kb
input:
81665969 919836918
output:
3 -1 55099735 26566235
result:
ok Correct
Test #15:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
470578680 280387800
output:
2 454969577 15609103
result:
ok Correct
Test #16:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
58450340 803305503
output:
2 434094898 -375644558
result:
ok Correct
Test #17:
score: 0
Accepted
time: 116ms
memory: 3600kb
input:
125896113 323676210
output:
3 1 22956403 102939709
result:
ok Correct
Test #18:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
381905348 434752500
output:
2 252688441 129216907
result:
ok Correct
Test #19:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
78916498 653897673
output:
1 78916498
result:
ok Correct
Test #20:
score: 0
Accepted
time: 118ms
memory: 3532kb
input:
35787885 270845190
output:
3 1 93533527 -57745643
result:
ok Correct
Extra Test:
score: 0
Extra Test Passed