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>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
ll a,b;
bool swapped;
bool is_prime(ll x) {
if(x == 0) return 0;
for(ll i = 2; i * i <= x; ++i) {
if(x % i == 0) return 0;
}
return 1;
}
int main() {_
cin >> a >> b;
if(a > b) {
swap(a,b);
swapped = 1;
}
bool ok = 0;
for(ll i = a; i <= b; i+=2) {
if(!is_prime(i)) {
break;
}
if(i == b) ok = 1;
}
vector<ll>ans = {};
if(ok) {
for(ll i = a; i <= b; i+=2) {
ans.PB(i);
}
} else {
ans.PB(a);
bool jump = (a == 2);
if(!jump && is_prime(a-2)) {
jump = 1;
ans.PB(2);
} else if(is_prime(a+2)) {
jump = 1;
ans.PB(a+2);
ans.PB(2);
}
if(!jump) {
cout << "-1";
return 0;
}
jump = 0;
if(is_prime(b - 2)) {
ans.PB(b);
jump = 1;
} else if(is_prime(b+2)) {
ans.PB(b+2);
ans.PB(b);
jump = 1;
}
if(!jump) {
cout << "-1";
return 0;
}
}
cout << (int)ans.size() << "\n";
if(swapped) reverse(ans.begin(),ans.end());
for(auto x : ans) {
cout << x << " ";
}
}
# | 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... |