QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#512124 | #9167. Coprime Array | ucup-team3699# | AC ✓ | 139ms | 3832kb | C++20 | 1.6kb | 2024-08-10 13:35:38 | 2024-08-10 13:35:39 |
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: 3540kb
input:
9 6
output:
3 1 494763289 -494763281
result:
ok Correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
14 34
output:
2 300253713 -300253699
result:
ok Correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
1000000000 223092870
output:
2 460871093 539128907
result:
ok Correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
2 1000000000
output:
2 328973513 -328973511
result:
ok Correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
649557664 933437700
output:
2 171216293 478341371
result:
ok Correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
33396678 777360870
output:
2 194995529 -161598851
result:
ok Correct
Test #7:
score: 0
Accepted
time: 118ms
memory: 3548kb
input:
48205845 903124530
output:
3 -1 396083153 -347877307
result:
ok Correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
251037078 505905400
output:
2 45525797 205511281
result:
ok Correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
30022920 172746860
output:
2 96223497 -66200577
result:
ok Correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
63639298 808058790
output:
2 241288199 -177648901
result:
ok Correct
Test #11:
score: 0
Accepted
time: 120ms
memory: 3596kb
input:
76579017 362768406
output:
3 -1 388016819 -311437801
result:
ok Correct
Test #12:
score: 0
Accepted
time: 139ms
memory: 3604kb
input:
40423669 121437778
output:
3 -1 180553179 -140129509
result:
ok Correct
Test #13:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
449277309 720915195
output:
2 276073331 173203978
result:
ok Correct
Test #14:
score: 0
Accepted
time: 121ms
memory: 3832kb
input:
81665969 919836918
output:
3 -1 328040107 -246374137
result:
ok Correct
Test #15:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
470578680 280387800
output:
2 34751441 435827239
result:
ok Correct
Test #16:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
58450340 803305503
output:
2 37751239 20699101
result:
ok Correct
Test #17:
score: 0
Accepted
time: 121ms
memory: 3592kb
input:
125896113 323676210
output:
3 -1 265758281 -139862167
result:
ok Correct
Test #18:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
381905348 434752500
output:
2 167757241 214148107
result:
ok Correct
Test #19:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
78916498 653897673
output:
1 78916498
result:
ok Correct
Test #20:
score: 0
Accepted
time: 118ms
memory: 3488kb
input:
35787885 270845190
output:
3 -1 9453023 26334863
result:
ok Correct
Extra Test:
score: 0
Extra Test Passed