#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){
llo j=2;
while(j*j<=aa){
if(aa%j==0){
return 0;
}
j+=1;
}
return 1;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
llo a,b;
cin>>a>>b;
llo stt=0;
if(a>b){
swap(a,b);
stt=1;
}
if(a==b){
cout<<1<<endl;
cout<<a<<endl;
}
else if(a>2 and b>2){
if(abs(a-b)>6){
cout<<-1<<endl;
return 0;
}
llo st=1;
llo co=0;
for(llo i=a;i<=b;i+=2){
co+=1;
if(ip(i)==0){
st=0;
}
}
if(st==0){
cout<<-1<<endl;
}
else{
cout<<co<<endl;
if(stt==0){
for(llo i=a;i<=b;i+=2){
cout<<i<<" ";
}
cout<<endl;
}
else{
for(llo i=b;i>=a;i-=2){
cout<<i<<" ";
}
cout<<endl;
}
}
}
else{
llo ind=-1;
llo so=1;
for(llo i=b;i>=max(b-6,a);i-=2){
if(ip(i)==0){
so=0;
break;
}
if(ip(abs(i-a))){
ind=i;
break;
}
}
if(ind==-1 or so==0){
cout<<-1<<endl;
}
else{
llo co=(b-ind)/2;
co+=1;
if(ind>a){
co+=1;
}
cout<<co<<endl;
if(stt==0){
cout<<a<<" ";
if(ind>a){
cout<<ind<<" ";
}
for(llo i=ind+2;i<=b;i+=2){
cout<<i<<" ";
}
cout<<endl;
}
else{
for(llo i=b;i>=ind+2;i-=2){
cout<<i<<" ";
}
cout<<ind<<" ";
if(ind>a){
cout<<a<<" ";
}
cout<<endl;
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |