Submission #404563

#TimeUsernameProblemLanguageResultExecution timeMemory
404563penguinhackerLutrija (COCI19_lutrija)C++14
70 / 70
342 ms296 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...