QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#512124#9167. Coprime Arrayucup-team3699#AC ✓139ms3860kbC++201.6kb2024-08-10 13:35:382024-10-14 07:51:53

Judging History

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

  • [2024-10-14 07:51:53]
  • 管理员手动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:139ms
  • 内存:3860kb
  • [2024-08-11 17:38:28]
  • hack成功,自动添加数据
  • (/hack/775)
  • [2024-08-10 13:35:39]
  • 评测
  • 测评结果:100
  • 用时:139ms
  • 内存:3832kb
  • [2024-08-10 13:35:38]
  • 提交

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,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 25ms
memory: 3816kb

input:

9 6

output:

3
-1 119266631 -119266621

result:

ok Correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

14 34

output:

2
315684069 -315684055

result:

ok Correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 3860kb

input:

1000000000 223092870

output:

2
257697827 742302173

result:

ok Correct

Test #4:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

2 1000000000

output:

2
498418059 -498418057

result:

ok Correct

Test #5:

score: 0
Accepted
time: 0ms
memory: 3856kb

input:

649557664 933437700

output:

2
375259607 274298057

result:

ok Correct

Test #6:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

33396678 777360870

output:

2
294588871 -261192193

result:

ok Correct

Test #7:

score: 0
Accepted
time: 118ms
memory: 3548kb

input:

48205845 903124530

output:

3
1 33827713 14378131

result:

ok Correct

Test #8:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

251037078 505905400

output:

2
20136957 230900121

result:

ok Correct

Test #9:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

30022920 172746860

output:

2
121153431 -91130511

result:

ok Correct

Test #10:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

63639298 808058790

output:

2
261605909 -197966611

result:

ok Correct

Test #11:

score: 0
Accepted
time: 120ms
memory: 3552kb

input:

76579017 362768406

output:

3
1 51325927 25253089

result:

ok Correct

Test #12:

score: 0
Accepted
time: 139ms
memory: 3504kb

input:

40423669 121437778

output:

3
-1 242317913 -201894243

result:

ok Correct

Test #13:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

449277309 720915195

output:

2
487433972 -38156663

result:

ok Correct

Test #14:

score: 0
Accepted
time: 121ms
memory: 3620kb

input:

81665969 919836918

output:

3
-1 252246103 -170580133

result:

ok Correct

Test #15:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

470578680 280387800

output:

2
393347369 77231311

result:

ok Correct

Test #16:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

58450340 803305503

output:

2
457115212 -398664872

result:

ok Correct

Test #17:

score: 0
Accepted
time: 121ms
memory: 3856kb

input:

125896113 323676210

output:

3
1 216553951 -90657839

result:

ok Correct

Test #18:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

381905348 434752500

output:

2
77402911 304502437

result:

ok Correct

Test #19:

score: 0
Accepted
time: 1ms
memory: 3620kb

input:

78916498 653897673

output:

1
78916498

result:

ok Correct

Test #20:

score: 0
Accepted
time: 117ms
memory: 3612kb

input:

35787885 270845190

output:

3
-1 96456713 -60668827

result:

ok Correct

Extra Test:

score: 0
Extra Test Passed