Submission #516705

# Submission time Handle Problem Language Result Execution time Memory
516705 2022-01-22T01:04:04 Z KoD Lutrija (COCI19_lutrija) C++17
70 / 70
152 ms 324 KB
#include <bits/stdc++.h>

using std::vector;
using std::array;
using std::pair;
using std::tuple;

using i64 = std::int64_t;

constexpr bool is_prime(const i64 x) {
    if (x <= 1) {
        return false;
    }
    for (i64 i = 2; i * i <= x; ++i) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}

template <class T> void println(const T& x) {
    std::cout << x << '\n';
}

template <class T, class... Arg> void println(const T& x, const Arg&... args) {
    std::cout << x << ' ';
    println(args...);
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 A, B;
    std::cin >> A >> B;
    if (is_prime(std::abs(A - B))) {
        println(2);
        println(A, B);
        return 0;
    }
    const bool x = is_prime(A + 2), y = is_prime(A - 2);
    const bool z = is_prime(B + 2), w = is_prime(B - 2);
    if (x and z) {
        println(5);
        println(A, A + 2, 2, B + 2, B);
        return 0;
    }
    if (x and w) {
        println(4);
        println(A, A + 2, 2, B);
        return 0;
    }
    if (y and z) {
        println(4);
        println(A, 2, B + 2, B);
        return 0;
    }
    if (y and w) {
        println(3);
        println(A, 2, B);
        return 0;
    }
    if (A == 2 and z) {
        println(3);
        println(2, B + 2, B);
        return 0;
    }
    if (B == 2 and x) {
        println(3);
        println(A, A + 2, 2);
        return 0;
    }
    std::cout << -1 << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 292 KB Output is correct
2 Correct 87 ms 296 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 296 KB Output is correct
2 Correct 82 ms 292 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 296 KB Output is correct
2 Correct 78 ms 208 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 208 KB Output is correct
2 Correct 64 ms 296 KB Output is correct
3 Correct 1 ms 208 KB Output is correct