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;
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define LOGN 25
#define MAXN 200005
bool isPrime(ll x) {
if (x == 1)
return false;
for (ll i = 2; i * i <= x; i++)
if (x % i == 0)
return false;
return true;
}
int main() {
fast
ll A, B;
cin >> A >> B;
if (A == 2 && B == 2) {
cout << "3\n2 5 2" << endl;
return 0;
} else if (A != 2 && B != 2) {
if (isPrime(abs(A-B))) {
cout << "2\n" << A << " " << B << endl;
return 0;
} else if (isPrime(abs(A-2)) && isPrime(abs(B-2))) {
cout << "3\n" << A << " 2 " << B << endl;
return 0;
}
} else if (A == 2 && B != 2) {
for (ll i = B-2; i > 2; i-=2) {
if (!isPrime(i) || (2 + (B-i)/2 > 30))
break;
if (isPrime(i) && isPrime(i-2)) {
cout << 2 + (B-i)/2 << endl;
cout << "2 ";
for (ll j = i; j <= B; j += 2)
cout << j << " ";
cout << endl;
return 0;
}
}
for (ll i = B+2; i <= 1e14; i+=2) {
if (!isPrime(i) || (2 + (i-B)/2 > 30))
break;
if (isPrime(i) && isPrime(i-2)) {
cout << 2 + (i-B)/2 << endl;
cout << "2 ";
for (ll j = i; j >= B; j -= 2)
cout << j << " ";
cout << endl;
return 0;
}
}
} else if (A != 2 && B == 2) {
for (ll i = A-2; i > 2; i-=2) {
if (!isPrime(i) || (2 + (A-i)/2 > 30))
break;
if (isPrime(i) && isPrime(i-2)) {
cout << 2 + (A-i)/2 << endl;
for (ll j = A; j >= i; j -= 2)
cout << j << " ";
cout << "2\n";
return 0;
}
}
for (ll i = A+2; i <= 1e14; i+=2) {
if (!isPrime(i) || (2 + (i-A)/2 > 30))
break;
if (isPrime(i) && isPrime(i-2)) {
cout << 2 + (i-A)/2 << endl;
for (ll j = A; j <= i; j += 2)
cout << j << " ";
cout << "2\n";
return 0;
}
}
}
cout << -1 << endl;
}
# | 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... |