QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#512069 | #9167. Coprime Array | ucup-team3699# | RE | 0ms | 0kb | C++20 | 1.4kb | 2024-08-10 13:25:28 | 2024-08-10 13:25:28 |
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 200005
#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;
}
}
}
assert(!add);
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
9 6