Submission #1370242

#TimeUsernameProblemLanguageResultExecution timeMemory
1370242FaresSTHLutrija (COCI19_lutrija)C++20
Compilation error
0 ms0 KiB
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
#define S second
#define F first
bool prime(ll x){
    if(x<2)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(ll i=3;i*i<=x;i+=2)if(x%i==0)return 0;
    return 1;
}
vector<ll>sol(ll a,ll b){
    if(a==2){
        if(prime(b-a))res={a,b};
        else if(prime(b+a))res={a,b+2,b};
        else return {};
    }
    vector<ll>res;
    if(prime(a-2)){
        res={a,a+2};
        auto q=sol(2,b);
        if(q.empty())return {};
        for(ll i:sol(2,b))res.push_back(i);
    }
    else if(prime(a+2)){
        res={a,a+2};
        auto q=sol(2,b);
        if(q.empty())return {};
        for(ll i:sol(2,b))res.push_back(i);
    }
    return res;
}
int main(){
    cin.tie(0)->sync_with_stdio(0);
    ll a,b;
    cin>>a>>b;
    bool swp=a>b;
    if(a>b)swap(a,b);
    auto res=sol(a,b);
    if(res.empty())return cout<<-1,0;
    cout<<res.size()<<'\n';
    if(swp)reverse(res.begin(),res.end());
    for(ll i:res)cout<<i<<' ';
}

Compilation message (stderr)

lutrija.cpp: In function 'std::vector<long long int> sol(ll, ll)':
lutrija.cpp:15:23: error: 'res' was not declared in this scope
   15 |         if(prime(b-a))res={a,b};
      |                       ^~~
lutrija.cpp:16:28: error: 'res' was not declared in this scope
   16 |         else if(prime(b+a))res={a,b+2,b};
      |                            ^~~