#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
322 ms |
284 KB |
Output is correct |
2 |
Correct |
98 ms |
292 KB |
Output is correct |
3 |
Correct |
195 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
312 ms |
288 KB |
Output is correct |
2 |
Correct |
96 ms |
204 KB |
Output is correct |
3 |
Correct |
140 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
342 ms |
204 KB |
Output is correct |
2 |
Correct |
89 ms |
288 KB |
Output is correct |
3 |
Correct |
128 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
251 ms |
292 KB |
Output is correct |
2 |
Correct |
72 ms |
296 KB |
Output is correct |
3 |
Correct |
46 ms |
204 KB |
Output is correct |