QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#513040 | #9167. Coprime Array | ucup-team1264# | TL | 0ms | 3816kb | C++20 | 2.1kb | 2024-08-10 16:43:20 | 2024-08-10 16:43:21 |
Judging History
answer
// https://www.youtube.com/watch?v=wthasN45KuY
// You said I’d fly away
// But my walls have kept me down
// Now I’m lost and I’m afraid
// And I’m close to hit the ground
//
// You said I’d fly away
// You said I’d fly anywhere
// But I keep on Falling
#ifndef ONLINE_JUDGE
#include "templates/debug.hpp"
#else
#define debug(...)
#endif
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
#define int i64
void solve() {
int s, x; cin >> s >> x;
if (gcd(s, x) == 1) {
cout << 1 << "\n";
cout << s << "\n";
}
// Goldbach's conjecture
if (x <= 20000) {
vector<int> dp(x + 1, 1e9 + 7), fa(x + 1, -1);
dp[0] = 0;
vector<int> cop_nums;
dp[1] = 1; cop_nums.push_back(1); fa[1] = 1;
for (int i = 2; i <= x; i++) {
if (gcd(i, x) == 1) {
dp[i] = 1;
cop_nums.push_back(i);
fa[i] = i;
continue;
}
for (int cop: cop_nums) {
if (dp[i - cop] + 1 < dp[i]) {
dp[i] = dp[i - cop] + 1;
fa[i] = cop;
}
}
}
debug(dp);
cout << dp[s % x] << "\n";
vector<int> ans;
while (s % x != 0) {
ans.push_back(fa[s % x]);
s -= fa[s % x];
}
ans[0] += s;
for (int x: ans) cout << x << " ";
cout << "\n";
} else {
cout << 2 << "\n";
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
while (true){
int t = rng() % (x - 1) + 1;
if (gcd(t, x) == 1 && gcd(s - t, x) == 1) {
cout << t << " " << s - t << "\n";
return;
}
}
}
}
#undef int
// Make bold hypotheses and verify carefully
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3816kb
input:
9 6
output:
3 7 1 1
result:
ok Correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
14 34
output:
2 1 13
result:
ok Correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
1000000000 223092870
output:
2 138778631 861221369
result:
ok Correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
2 1000000000
output:
2 345340223 -345340221
result:
ok Correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
649557664 933437700
output:
2 198959027 450598637
result:
ok Correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
33396678 777360870
output:
2 137042131 -103645453
result:
ok Correct
Test #7:
score: -100
Time Limit Exceeded
input:
48205845 903124530