#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define endl "\n"
llo ip(llo aa){
if(aa==1){
return 0;
}
llo j=2;
while(j*j<=aa){
if(aa%j==0){
return 0;
}
j+=1;
}
return 1;
}
vector<llo> solve(llo a,llo b){
if(a==b){
return {a};
}
if(a==2){
if(ip(b-a)){
return {a,b};
}
if(ip(b+2-a) and ip(b+2)){
return {a,b+2,b};
}
if(b-2>a){
if(ip(b-2-a) and ip(b-2)){
return {a,b-2,b};
}
}
return {-1};
}
else{
llo st=1;
if(b-a<=4){
for(llo i=a;i<=b;i+=2){
if(ip(i)==0){
st=0;
}
}
}
else{
st=0;
}
if(st){
vector<llo> ans2;
for(llo i=a;i<=b;i+=2){
ans2.pb(i);
}
return ans2;
}
vector<llo> x=solve(2,a);
vector<llo> y=solve(2,b);
if(x[0]==-1 or y[0]==-1){
return {-1};
}
reverse(x.begin(),x.end());
vector<llo> ans3;
for(auto j:x){
if(j>2){
ans3.pb(j);
}
}
for(auto j:y){
ans3.pb(j);
}
return ans3;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
llo a,b;
cin>>a>>b;
vector<llo> ans=solve(min(a,b),max(b,a));
if(ans[0]==-1){
cout<<-1<<endl;
return 0;
}
cout<<ans.size()<<endl;
if(a>b){
reverse(ans.begin(),ans.end());
}
for(auto j:ans){
cout<<j<<" ";
}
cout<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |