#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long num) {
long long d;
if (num % 2 == 0 || num <= 1)
return 0;
for (d = 3; d * d <= num; d++) {
if (num % d == 0) {
return 0;
}
}
return 1;
}
int main() {
long long a, b, AP2, AM2, BP2, BM2, nr;
cin >> a >> b;
AP2 = isPrime(a + 2);
AM2 = isPrime(a - 2);
BP2 = isPrime(b + 2);
BM2 = isPrime(b - 2);
if (a != 2 && !AP2 && !AM2) {
cout << "-1";
} else if (b != 2 && !BP2 && !BM2) {
cout << "-1";
} else {
nr = 1;
if(AM2){
nr++;
} else if(AP2){
nr += 2;
}
if(BM2){
nr++;
} else if(BP2){
nr += 2;
}
// AM2 = 1 AP2 = 1
// BM2 = 0 BP2 = 1
cout << nr << '\n';
/* if(AP2){
cout << a << ' ' << a + 2 << ' ';
} else if(AM2){
cout << a << ' ';
}
cout << "2";
if(BP2){
cout << ' ' << b + 2 << ' ' << b;
} else if(BM2){
cout << ' ' << b;
} */
cout << (AM2 ? to_string( (long long) a) + ' ' : (AP2 ? to_string( (long long) a) + ' ' + to_string( (long long) a + 2) + ' ' : ""))
<< "2"
<< (BM2 ? ' ' + to_string( (long long) b) : (BP2 ? ' ' + to_string( (long long) b + 2) + ' ' + to_string( (long long) b) : ""));
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
288 KB |
Output is correct |
2 |
Correct |
78 ms |
280 KB |
Output is correct |
3 |
Correct |
156 ms |
280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
126 ms |
280 KB |
Output is correct |
2 |
Correct |
76 ms |
280 KB |
Output is correct |
3 |
Correct |
113 ms |
276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
284 KB |
Output is correct |
2 |
Correct |
74 ms |
280 KB |
Output is correct |
3 |
Correct |
104 ms |
284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
296 KB |
Output is correct |
2 |
Correct |
57 ms |
212 KB |
Output is correct |
3 |
Correct |
37 ms |
212 KB |
Output is correct |