Submission #645325

#TimeUsernameProblemLanguageResultExecution timeMemory
645325Hacv16Lutrija (COCI19_lutrija)C++17
0 / 70
5 ms480 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAX = 2e7 + 15; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; #define pb push_back #define sz(x) (int) x.size() #define fr first #define sc second #define mp make_pair #define all(x) x.begin(), x.end() #define dbg(x) cerr << #x << ": " << "[ " << x << " ]\n" ll l, r, ind[MAX]; bool notPrime[MAX], inv, pos; vector<ll> primes, ans; void Crivo(ll n){ notPrime[1] = true; for(int i = 2; i <= n; i++){ if(notPrime[i]) continue; primes.push_back(i); ind[i] = sz(primes) - 1; for(int j = 2; i * j <= n; j++) notPrime[i * j] = true; } } void MakeforTwo(ll x, ll id){ ans.push_back(x); if(x == 2){pos = true; return;} if(!notPrime[x - 2]) MakeforTwo(2, 0); ll diff = x - primes[id - 1]; if(diff == 2) MakeforTwo(primes[id - 1], id - 1); } void MakeArray(ll x, ll id){ ans.push_back(x); if(x == l){pos = true; return;} if(id == 0) return; ll diff = x - primes[id - 1]; if(diff == 2) MakeArray(primes[id - 1], id - 1); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); Crivo(1050); cin >> l >> r; if(l == 2 || r == 2){ if(r == 2) swap(l, r), inv = true; MakeforTwo(r, ind[r]); }else{ if(l > r) swap(l, r), inv = true; MakeArray(r, ind[r]); } if(!inv) reverse(all(ans)); if(!pos){ cout << -1 << '\n'; }else{ cout << sz(ans) << '\n'; for(auto x : ans) cout << x << ' '; cout << '\n'; } 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...