QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#512145#9167. Coprime Arrayucup-team3699#RE 0ms0kbC++201.4kb2024-08-10 13:40:182024-08-10 13:40:21

Judging History

你现在查看的是最新测评结果

  • [2024-08-11 17:38:28]
  • hack成功,自动添加数据
  • (/hack/775)
  • [2024-08-10 13:40:21]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-08-10 13:40:18]
  • 提交

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

output:


result: