Submission #445285

#TimeUsernameProblemLanguageResultExecution timeMemory
445285colossal_pepeLutrija (COCI19_lutrija)C++17
7 / 70
270 ms276 KiB
#include <iostream> using namespace std; typedef long long ll; ll a, b; bool isPrime(ll x) { if (x < 2) return 0; for (ll i = 2; i * i <= x; i++) { if (x%i == 0) return 0; } return 1; } bool check(ll arr[], int n) { for (int i = 1; i < n; i++) { if (not isPrime(arr[i]) or not isPrime(abs(arr[i] - arr[i - 1]))) return 0; } return 1; } void printAns(ll arr[], int n) { for (int i = 0; i < n; i++) { cout << arr[i] << ' '; } cout << endl; } int main() { cin >> a >> b; if (isPrime(abs(a - b))) { cout << 2 << endl; cout << a << ' ' << b << endl; } else if (a == 2 or b == 2) { ll opt1[3] = {a, max(a, b) + 2, b}; ll opt2[3] = {a, max(a, b) - 2, b}; if (check(opt1, 3)) { cout << 3 << endl; printAns(opt1, 3); } else if (check(opt2, 3)) { cout << 3 << endl; printAns(opt2, 3); } else { cout << -1 << endl; } } else { ll opt1[4] = {a, 2, b + 2, b}; ll opt2[4] = {a, 2, b - 2, b}; ll opt3[4] = {a, a + 2, 2, b}; ll opt4[4] = {a, a - 2, 2, b}; if (check(opt1, 4)) { cout << 4 << endl; printAns(opt1, 4); } else if (check(opt2, 4)) { cout << 4 << endl; printAns(opt2, 4); } else if (check(opt3, 4)) { cout << 4 << endl; printAns(opt3, 4); } else if (check(opt4, 4)) { cout << 4 << endl; printAns(opt4, 4); } else { cout << -1 << endl; } } 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...