This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
using namespace std;
typedef long long ll;
ll a, b;
bool isPrime(ll x) {
if (x < 2) return 0;
for (ll i = 2; i * i <= x; i++) {
if (x%i == 0) return 0;
}
return 1;
}
bool check(ll arr[], int n) {
for (int i = 1; i < n; i++) {
if (not isPrime(arr[i]) or not isPrime(abs(arr[i] - arr[i - 1]))) return 0;
}
return 1;
}
void printAns(ll arr[], int n) {
cout << n << endl;
for (int i = 0; i < n; i++) {
cout << arr[i] << ' ';
}
cout << endl;
}
int main() {
cin >> a >> b;
if (isPrime(abs(a - b))) {
cout << 2 << endl;
cout << a << ' ' << b << endl;
} else {
ll opt1[3] = {a, max(a, b) + 2, b};
ll opt2[3] = {a, max(a, b) - 2, b};
ll opt3[4] = {a, 2, b + 2, b};
ll opt4[4] = {a, 2, b - 2, b};
ll opt5[4] = {a, b + 2, 2, b};
ll opt6[4] = {a, b - 2, 2, b};
ll opt7[4] = {a, a + 2, 2, b};
ll opt8[4] = {a, a - 2, 2, b};
ll opt9[4] = {a, 2, a + 2, b};
ll opt10[4] = {a, 2, a - 2, b};
if (check(opt1, 3)) {
printAns(opt1, 3);
} else if (check(opt2, 3)) {
printAns(opt2, 3);
} else if (check(opt3, 4)) {
printAns(opt3, 4);
} else if (check(opt4, 4)) {
printAns(opt4, 4);
} else if (check(opt5, 4)) {
printAns(opt5, 4);
} else if (check(opt6, 4)) {
printAns(opt6, 4);
} else if (check(opt7, 4)) {
printAns(opt7, 4);
} else if (check(opt8, 4)) {
printAns(opt8, 4);
} else if (check(opt9, 4)) {
printAns(opt9, 4);
} else if (check(opt10, 4)) {
printAns(opt10, 4);
} else {
cout << -1 << endl;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |