Submission #782093

#TimeUsernameProblemLanguageResultExecution timeMemory
782093serifefedartarLutrija (COCI19_lutrija)C++17
7 / 70
1 ms316 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); typedef long long ll; #define f first #define s second #define LOGN 25 #define MAXN 200005 bool isPrime(ll x) { for (ll i = 2; i * i <= x; i++) if (x % i == 0) return false; return true; } int main() { fast ll A, B; cin >> A >> B; if (A == 2 && B == 2) { cout << "3\n2 5 2" << endl; return 0; } else if (A != 2 && B != 2) { if (isPrime(abs(A-B))) { cout << "2\n" << A << " " << B << endl; return 0; } else if (isPrime(abs(A-2)) && isPrime(abs(B-2))) { cout << "3\n" << A << " 2 " << B << endl; return 0; } } else if (A == 2 && B != 2) { for (ll i = B-2; i > 2; i-=2) { if (!isPrime(i) || (2 + (B-i)/2 > 30)) break; if (isPrime(i)) { cout << 2 + (B-i)/2 << endl; cout << "2 "; for (int j = i; j <= B; j += 2) cout << j << " "; cout << endl; return 0; } } for (ll i = B+2; i <= 1e14; i+=2) { if (!isPrime(i) || (2 + (i-B)/2 > 30)) break; if (isPrime(i)) { cout << 2 + (i-B)/2 << endl; cout << "2 "; for (int j = i; j >= B; j -= 2) cout << j << " "; cout << endl; return 0; } } } else if (A != 2 && B == 2) { for (ll i = A-2; i > 2; i-=2) { if (!isPrime(i) || (2 + (A-i)/2 > 30)) break; if (isPrime(i)) { cout << 2 + (A-i)/2 << endl; for (int j = A; j >= i; j -= 2) cout << j << " "; cout << "2\n"; return 0; } } for (ll i = A+2; i <= 1e14; i+=2) { if (!isPrime(i) || (2 + (i-A)/2 > 30)) break; if (isPrime(i)) { cout << 2 + (i-A)/2 << endl; for (int j = A; j <= i; j += 2) cout << j << " "; cout << "2\n"; return 0; } } } cout << -1 << endl; }
#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...