#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) {
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 if (a == 2 or b == 2) {
ll opt1[3] = {a, max(a, b) + 2, b};
ll opt2[3] = {a, max(a, b) - 2, b};
if (check(opt1, 3)) {
cout << 3 << endl;
printAns(opt1, 3);
} else if (check(opt2, 3)) {
cout << 3 << endl;
printAns(opt2, 3);
} else {
cout << -1 << endl;
}
} else {
ll opt1[4] = {a, 2, b + 2, b};
ll opt2[4] = {a, 2, b - 2, b};
ll opt3[4] = {a, a + 2, 2, b};
ll opt4[4] = {a, a - 2, 2, b};
if (check(opt1, 4)) {
cout << 4 << endl;
printAns(opt1, 4);
} else if (check(opt2, 4)) {
cout << 4 << endl;
printAns(opt2, 4);
} else if (check(opt3, 4)) {
cout << 4 << endl;
printAns(opt3, 4);
} else if (check(opt4, 4)) {
cout << 4 << endl;
printAns(opt4, 4);
} else {
cout << -1 << endl;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
231 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
237 ms |
276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
270 ms |
272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
219 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |