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>
#pragma GCC optimize("O3")
#define ll long long
#define pii pair<ll, ll>
using namespace std;
const ll MAX = 1e14;
ll a, b;
bool isPrime(ll n){
if(n <= 1) return false;
for (int i = 2; 1ll * i * i <= n; i++)
{
if(n % i == 0){
return false;
}
}
return true;
}
vector<ll> ans;
void f(ll n){
if(n == 2){
if(isPrime(b - 2)){
ans.push_back(b);
}
else if(b + 2 <= MAX && isPrime(b + 2)){
ans.push_back(b + 2);
ans.push_back(b);
}
else{
ans.clear();
}
return;
}
if(isPrime(n - 2)){
ans.push_back(2);
f(2);
}
else if(n + 2 <= MAX && isPrime(n + 2)){
ans.push_back(n + 2);
f(n + 2);
}
else{
ans.clear();
}
}
int main(){
cin >> a >> b;
ans.push_back(a);
f(a);
if(ans.size() == 0){
cout << -1 << '\n';
}
else{
cout << ans.size() << '\n';
for(ll a:ans){
cout << a << ' ';
}
}
}
# | 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... |