Submission #445285

# Submission time Handle Problem Language Result Execution time Memory
445285 2021-07-17T10:00:42 Z colossal_pepe Lutrija (COCI19_lutrija) C++17
7 / 70
270 ms 276 KB
#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 time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 231 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 237 ms 276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 270 ms 272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 219 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -