Submission #782174

# Submission time Handle Problem Language Result Execution time Memory
782174 2023-07-13T16:03:02 Z serifefedartar Lutrija (COCI19_lutrija) C++17
7 / 70
1 ms 212 KB
#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) {
    if (x <= 1)
        return false;

    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 (isPrime(abs(A-B))) {
        cout << "2\n" << A << " " << B;
        return 0;
    } else if (A == 2 && B == 2) {
        cout << "3\n2 5 2";
        return 0;
    } else if (A != 2 && B != 2) {
        if (isPrime(abs(A-B))) {
            cout << "2\n" << A << " " << B;
            return 0;
        } else if (isPrime(abs(A-2)) && isPrime(abs(B-2))) {
            cout << "3\n" << A << " 2 " << B;
            return 0;
        }
    } else if (A == 2 && B != 2) {
        for (ll i = B; i > 2; i-=2) {
            if (!isPrime(i) || (2 + (B-i)/2 > 30))
                break;
            if (isPrime(i) && isPrime(i-2)) {
                cout << 2 + (B-i)/2 << endl;
                cout << "2";
                for (ll j = i; j <= B; j += 2)
                    cout << " " << j;
                return 0;
            }
        }
        for (ll i = B; i <= 1e14; i+=2) {
            if (!isPrime(i) || (2 + (i-B)/2 > 30))
                break;
            if (isPrime(i) && isPrime(i-2)) {
                cout << 2 + (i-B)/2 << endl;
                cout << "2";
                for (ll j = i; j >= B; j -= 2)
                    cout << " " << j;
                return 0;
            }
        }
    } else if (A != 2 && B == 2) {
        for (ll i = A; i > 2; i-=2) {
            if (!isPrime(i) || (2 + (A-i)/2 > 30))
                break;
            if (isPrime(i) && isPrime(i-2)) {
                cout << 2 + (A-i)/2 << endl;
                for (ll j = A; j >= i; j -= 2)
                    cout << j << " ";
                cout << "2";
                return 0;
            }
        }
        for (ll i = A; i <= 1e14; i+=2) {
            if (!isPrime(i) || (2 + (i-A)/2 > 30))
                break;
            if (isPrime(i) && isPrime(i-2)) {
                cout << 2 + (i-A)/2 << endl;
                for (ll j = A; j <= i; j += 2)
                    cout << j << " ";
                cout << "2";
                return 0;
            }
        }
    }
    cout << -1 << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -