QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#512145 | #9167. Coprime Array | ucup-team3699# | RE | 0ms | 0kb | C++20 | 1.4kb | 2024-08-10 13:40:18 | 2024-08-10 13:40:21 |
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;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
9 6