This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll a, b, ans[5];
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() {
vector<int> v;
for (ll i: ans) {
if (i > 0) v.push_back(i);
}
for (int i = 1; i < v.size(); i++) {
if (not isPrime(v[i]) or not isPrime(abs(v[i] - v[i - 1]))) return 0;
}
return 1;
}
bool solve() {
ans[0] = a, ans[4] = b;
ll c1[3] = {0, a - 2, a + 2}, c2[2] = {0, 2}, c3[4] = {0, b - 2, b + 2};
for (ll p: c1) {
for (ll q: c2) {
for (ll r: c3) {
ans[1] = p, ans[2] = q, ans[3] = r;
if (check()) return 1;
}
}
}
return 0;
}
int main() {
cin >> a >> b;
if (solve()) {
int cnt = 0;
for (ll i: ans) {
if (i > 0) cnt++;
}
cout << cnt << endl;
for (ll i: ans) {
if (i > 0) cout << i << ' ';
}
cout << endl;
} else {
cout << -1 << endl;
}
return 0;
}
Compilation message (stderr)
lutrija.cpp: In function 'bool check()':
lutrija.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 1; i < v.size(); i++) {
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |