#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector <int> ans;
int isPrime(ll a) {
if(a < 2) return 0;
if(a <= 3) return 1;
for(int i = 2; i * i <= a; i++) {
if (a % i == 0) return 0;
}
return 1;
}
void finish() {
cout << -1;
exit(0);
}
void ex() {
exit(0);
}
void check(vector <ll> ans, vector<ll> ans1) {
ll a = ans.back();
ll b = ans1.back();
if(a <= 1 || b <= 1) return;
if(isPrime(abs(a-b))) {
cout << ans.size() + ans1.size() << "\n";
for(ll i : ans) cout << i << " ";
reverse(ans1.begin(), ans1.end());
for(ll i : ans1) cout << i << " ";
ex();
}
if(isPrime(a-2)) {
ans.push_back(2);
check(ans, ans1);
ans.pop_back();
}
if(isPrime(a+2)) {
ans.push_back(a+2);
check(ans, ans1);
ans.pop_back();
}
if(isPrime(b-2)) {
ans1.push_back(2);
check(ans, ans1);
ans1.pop_back();
}
if(isPrime(b+2)) {
ans1.push_back(b+2);
check(ans, ans1);
ans1.pop_back();
}
return;
}
int main() {
ll a, b;
cin >> a >> b;
if(a % 2 == 0 && b % 2 == 0) finish();
if(isPrime(abs(a-b))) {
cout << "2\n" << a << " " << b << "\n";
return 0;
}
vector <ll> ans, ans1;
ans.push_back(a);
ans1.push_back(b);
check(ans, ans1);
finish();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2043 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2045 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2027 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2021 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |