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 ll long long
#define ar array
ll a, b;
vector<ll> c={2}, p;
set<ll> vis;
bool prime(ll n) {
for (int i=2; (ll)i*i<=n; ++i)
if (n%i==0)
return 0;
return n>=2;
}
void add(ll n) {
c.push_back(n);
if (prime(n-2))
c.push_back(n-2);
if (prime(n+2))
c.push_back(n+2);
}
void dfs(ll u) {
p.push_back(u), vis.insert(u);
if (u==b) {
cout << p.size() << "\n";
for (ll i : p)
cout << i << " ";
exit(0);
}
for (ll v : c)
if (!vis.count(v)&&prime(abs(u-v)))
dfs(v);
p.pop_back();
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> a >> b;
add(a), add(b);
sort(c.begin(), c.end());
c.resize(unique(c.begin(), c.end())-c.begin());
dfs(a);
cout << -1;
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... |