QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#653084 | #9167. Coprime Array | woodie_0064# | AC ✓ | 0ms | 3876kb | C++20 | 1.3kb | 2024-10-18 19:32:27 | 2024-10-18 19:32:32 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e5 + 3;
typedef long long ll;
void work(){
int n,m;cin >> n >> m;
if(__gcd(n,m) == 1) {
cout << "1\n";
cout << n << '\n';
return;
}
vector <int> ans,r,a;
if(n % 2 && m % 2 == 0) {
ans.push_back(1);
n -= 1;
}
for(int i = 2;i * i <= m;i++) if(m % i == 0) {
r.push_back(i);
while(m % i == 0) m /= i;
}
if(m != 1) r.push_back(m);
for(const auto &x : r) {
if(n % x == 1) {
a.push_back(2);
}else a.push_back(1);
}
auto exgcd = [] (auto &&self,ll a,ll b,ll &x,ll &y) {
if(!b) {
x = 1;y = 0;
return a;
}
ll d = self(self,b,a % b,x,y);
ll t = x;
x = y;
y = t - (a / b) * y;
return d;
};
auto CRT = [&] () {
int k = a.size();
ll now = 1,res = 0;
for(int i = 0;i < k;i++) now = now * r[i];
for(int i = 0;i < k;i++) {
ll m = now / r[i],b,y;
exgcd(exgcd,m,r[i],b,y);
res = (res + a[i] * m * b % now) % now;
}
return (res % now + now) % now;
};
ans.push_back(CRT());
ans.push_back(n - ans.back());
cout << (int)ans.size() << '\n';
for(auto &x : ans) cout << x << ' ';
cout << '\n';
}
int main(){
// freopen("test.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
while(T--){
work();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3676kb
input:
9 6
output:
3 1 1 7
result:
ok Correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
14 34
output:
2 1 13
result:
ok Correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
1000000000 223092870
output:
2 148728581 851271419
result:
ok Correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
2 1000000000
output:
2 1 1
result:
ok Correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
649557664 933437700
output:
2 83981 649473683
result:
ok Correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
33396678 777360870
output:
2 1 33396677
result:
ok Correct
Test #7:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
48205845 903124530
output:
3 1 18811 48187033
result:
ok Correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
251037078 505905400
output:
2 1 251037077
result:
ok Correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
30022920 172746860
output:
2 1 30022919
result:
ok Correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
63639298 808058790
output:
2 248711 63390587
result:
ok Correct
Test #11:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
76579017 362768406
output:
3 1 1 76579015
result:
ok Correct
Test #12:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
40423669 121437778
output:
3 1 1 40423667
result:
ok Correct
Test #13:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
449277309 720915195
output:
2 1 449277308
result:
ok Correct
Test #14:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
81665969 919836918
output:
3 1 68069 81597899
result:
ok Correct
Test #15:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
470578680 280387800
output:
2 1 470578679
result:
ok Correct
Test #16:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
58450340 803305503
output:
2 1 58450339
result:
ok Correct
Test #17:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
125896113 323676210
output:
3 1 59281 125836831
result:
ok Correct
Test #18:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
381905348 434752500
output:
2 1 381905347
result:
ok Correct
Test #19:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
78916498 653897673
output:
1 78916498
result:
ok Correct
Test #20:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
35787885 270845190
output:
3 1 1 35787883
result:
ok Correct
Extra Test:
score: 0
Extra Test Passed