Submission #725428

# Submission time Handle Problem Language Result Execution time Memory
725428 2023-04-17T11:54:48 Z TheSahib Lutrija (COCI19_lutrija) C++14
70 / 70
267 ms 332 KB
#include <bits/stdc++.h>
 
#pragma GCC optimize("O3")
 
#define ll long long
#define pii pair<ll, ll>
 
using namespace std;


const ll MAX = 1e14;

ll a, b;

bool isPrime(ll n){
    if(n <= 1) return false;
    for (int i = 2; 1ll * i * i <= n; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}

vector<ll> ans;
void f(ll n){
    if(n == 2){
        if(isPrime(b - 2)){
            ans.push_back(b);
        }
        else if(b + 2 <= MAX && isPrime(b + 2)){
            ans.push_back(b + 2);
            ans.push_back(b);
        }
        else{
            ans.clear();
        }
        return;
    }

    if(isPrime(n - 2)){
        ans.push_back(2);
        f(2);
    }
    else if(n + 2 <= MAX && isPrime(n + 2)){
        ans.push_back(n + 2);
        f(n + 2);
    }
    else{
        ans.clear();
    }
}

int main(){
    cin >> a >> b;
    ans.push_back(a);
    f(a);
    if(ans.size() == 0){
        cout << -1 << '\n';
    }
    else{
        cout << ans.size() << '\n';
        for(ll a:ans){
            cout << a << ' ';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 224 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 276 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 267 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 206 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 193 ms 284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 242 ms 288 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 174 ms 276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 200 ms 280 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 61 ms 212 KB Output is correct