Submission #445288

# Submission time Handle Problem Language Result Execution time Memory
445288 2021-07-17T10:15:01 Z colossal_pepe Lutrija (COCI19_lutrija) C++17
7 / 70
521 ms 268 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) {
    cout << n << endl;
    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 {
        ll opt1[3] = {a, max(a, b) + 2, b};
        ll opt2[3] = {a, max(a, b) - 2, b};
        ll opt3[4] = {a, 2, b + 2, b};
        ll opt4[4] = {a, 2, b - 2, b};
        ll opt5[4] = {a, b + 2, 2, b};
        ll opt6[4] = {a, b - 2, 2, b};
        ll opt7[4] = {a, a + 2, 2, b};
        ll opt8[4] = {a, a - 2, 2, b};
        ll opt9[4] = {a, 2, a + 2, b};
        ll opt10[4] = {a, 2, a - 2, b};
        if (check(opt1, 3)) {
            printAns(opt1, 3);
        } else if (check(opt2, 3)) {
            printAns(opt2, 3);
        } else if (check(opt3, 4)) {
            printAns(opt3, 4);
        } else if (check(opt4, 4)) {
            printAns(opt4, 4);
        } else if (check(opt5, 4)) {
            printAns(opt5, 4);
        } else if (check(opt6, 4)) {
            printAns(opt6, 4);
        } else if (check(opt7, 4)) {
            printAns(opt7, 4);
        } else if (check(opt8, 4)) {
            printAns(opt8, 4);
        } else if (check(opt9, 4)) {
            printAns(opt9, 4);
        } else if (check(opt10, 4)) {
            printAns(opt10, 4);
        } else {
            cout << -1 << endl;
        }
    }
    return 0;
}
# 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 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 0 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 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 401 ms 268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 473 ms 264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 521 ms 268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 381 ms 268 KB Output isn't correct
2 Halted 0 ms 0 KB -