#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(a == 2 && b == 2) {ans.push_back(5); goto here;}
if(isPrime(abs(a-b))) {
here:
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() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
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 |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 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 |
Execution timed out |
2054 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2032 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2049 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2057 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |