QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#512141 | #9167. Coprime Array | ucup-team3699# | AC ✓ | 139ms | 3812kb | C++20 | 1.6kb | 2024-08-10 13:39:31 | 2024-10-14 07:51:54 |
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: 3524kb
input:
9 6
output:
3 -1 138415715 -138415705
result:
ok Correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
14 34
output:
2 228434187 -228434173
result:
ok Correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
1000000000 223092870
output:
2 99948851 900051149
result:
ok Correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
2 1000000000
output:
2 234145681 -234145679
result:
ok Correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
649557664 933437700
output:
2 87369731 562187933
result:
ok Correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
33396678 777360870
output:
2 152818459 -119421781
result:
ok Correct
Test #7:
score: 0
Accepted
time: 118ms
memory: 3596kb
input:
48205845 903124530
output:
3 1 228070663 -179864819
result:
ok Correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
251037078 505905400
output:
2 52193651 198843427
result:
ok Correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
30022920 172746860
output:
2 103454803 -73431883
result:
ok Correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
63639298 808058790
output:
2 375126701 -311487403
result:
ok Correct
Test #11:
score: 0
Accepted
time: 120ms
memory: 3592kb
input:
76579017 362768406
output:
3 1 66666595 9912421
result:
ok Correct
Test #12:
score: 0
Accepted
time: 139ms
memory: 3788kb
input:
40423669 121437778
output:
3 -1 133095395 -92671725
result:
ok Correct
Test #13:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
449277309 720915195
output:
2 113399722 335877587
result:
ok Correct
Test #14:
score: 0
Accepted
time: 121ms
memory: 3556kb
input:
81665969 919836918
output:
3 -1 48400987 33264983
result:
ok Correct
Test #15:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
470578680 280387800
output:
2 51083819 419494861
result:
ok Correct
Test #16:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
58450340 803305503
output:
2 47450668 10999672
result:
ok Correct
Test #17:
score: 0
Accepted
time: 120ms
memory: 3812kb
input:
125896113 323676210
output:
3 1 236082559 -110186447
result:
ok Correct
Test #18:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
381905348 434752500
output:
2 497105659 -115200311
result:
ok Correct
Test #19:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
78916498 653897673
output:
1 78916498
result:
ok Correct
Test #20:
score: 0
Accepted
time: 118ms
memory: 3604kb
input:
35787885 270845190
output:
3 1 255439963 -219652079
result:
ok Correct
Extra Test:
score: 0
Extra Test Passed