Submission #823914

# Submission time Handle Problem Language Result Execution time Memory
823914 2023-08-13T10:05:43 Z Sandarach151 Lutrija (COCI19_lutrija) C++17
0 / 70
1 ms 212 KB
#include<bits/stdc++.h>
using namespace std;

bool isPrime(long long x) {
    if (x < 2) return false; //All primes are above 2
    else if (x == 2) return true; //If its 2, its a prime
    else if (x % 2 == 0) return false; //If its even (other than 2), its not a prime -> used for speedup 
    for (int i = 3; i <= x/i; i+=2) { //Trial divide all odd numbers > 2 up till the square root of x
        if (x % i == 0) return false; //If a factor is found, x is not prime
    }
    return true; //If no factors are found, x is a prime
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long a, b;
    cin >> a >> b;
    bool res = true;
    vector<long long> vect;
    bool swapped = false;
    if(a%2==1 && b%2==1){
        if(a>b){
            swap(a, b);
            swapped = true;
        }
        for(int i=a; i<=b; i+=2){
            if(!isPrime(i)){
                res = false;
                break;
            }
            vect.push_back(i);
        }
    }
    else{
        if(a==2){
            swap(a, b);
            swapped = true;
        }
        if(isPrime(a) && isPrime(a+2)){
            vect.push_back(a);
            vect.push_back(a+2);
            vect.push_back(2);
        }
        else if(isPrime(a) && isPrime(a-2)){
            vect.push_back(a);
            vect.push_back(2);
        }
        else{
            res = false;
        }
    }
    if(!res){
        cout << -1 << '\n';
    }
    else{
        if(!swapped){
            cout << vect.size() << '\n';
            for(long long i=0LL; i< (long long) vect.size(); i++){
                cout << vect[i] << ' ';
            }
        }
        else{
            cout << vect.size() << '\n';
            for(long long i=vect.size()-1; i>=0; i--){
                cout << vect[i] << ' ';
            }
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 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 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 -