| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1370242 | FaresSTH | Lutrija (COCI19_lutrija) | C++20 | 0 ms | 0 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<<' ';
}