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 <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);
}
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;
}
if(a % 2 && b % 2) {
if(isPrime(a-2) && isPrime (b-2)) {cout << "5\n" << a << " 2 5 2 " << b << "\n"; return 0;}
else finish();
}
if(a % 2) {
if(isPrime(a + 2)) {cout << "3\n" << a << " " << a+2 << " " << b << "\n"; return 0;}
else if(isPrime(a-2)) {cout << "4\n " << a << " 2 " << a << " 2" << "\n"; return 0;}
else finish();
}
if(b % 2) {
if(isPrime(b + 2)) {cout << "3\n" << a << " " << b+2 << " " << b << "\n"; return 0;}
else if(isPrime(b-2)) {cout << "4\n " << "2 " << b << " 2 " << b << "\n"; return 0;}
else finish();
}
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... |