#include<bits/stdc++.h>
using namespace std;
bool isPrime(long long x) {
if (x < 2) return false; //All primes are above 2
else if (x == 2) return true; //If its 2, its a prime
else if (x % 2 == 0) return false; //If its even (other than 2), its not a prime -> used for speedup
for (int i = 3; i <= x/i; i+=2) { //Trial divide all odd numbers > 2 up till the square root of x
if (x % i == 0) return false; //If a factor is found, x is not prime
}
return true; //If no factors are found, x is a prime
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long a, b;
cin >> a >> b;
bool res = true;
vector<long long> vect;
bool swapped = false;
if(a%2==1 && b%2==1){
if(a>b){
swap(a, b);
swapped = true;
}
for(int i=a; i<=b; i+=2){
if(!isPrime(i)){
res = false;
break;
}
vect.push_back(i);
}
}
else{
if(a==2){
swap(a, b);
swapped = true;
}
if(isPrime(a) && isPrime(a+2)){
vect.push_back(a);
vect.push_back(a+2);
vect.push_back(2);
}
else if(isPrime(a) && isPrime(a-2)){
vect.push_back(a);
vect.push_back(2);
}
else{
res = false;
}
}
if(!res){
cout << -1;
}
else{
if(!swapped){
cout << vect.size() << '\n';
for(long long i=0LL; i< (long long) vect.size()-1; i++){
cout << vect[i] << ' ';
}
cout << vect[vect.size()-1];
}
else{
cout << vect.size() << '\n';
for(long long i=vect.size()-1; i>0; i--){
cout << vect[i] << ' ';
}
cout << vect[0];
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |