#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
bool prime(int x){
if(x <= 1) return false;
for(int i = 2; i * i <= x; i++){
if(x % i == 0) return false;
}
return true;
}
void solve(){
int a,b;
cin >> a >> b;
if(abs(a-b) == 2){
cout << "2\n" << a << ' ' << b << endl;
return;
}
if(a == 3 && b == 7){
cout << "3\n3 5 7";
}
else if(a == 7 && b == 3){
cout << "3\n7 5 3";
}
if(a == 2){
if(prime(b + 2)) cout << "3\n" << a << ' ' << b + 2 << ' ' << b << endl;
else if(prime(b - 2)) cout << "3\n" << a << ' ' << b - 2 << ' ' << b << endl;
else cout << -1 << endl;
return;
}
if(b == 2){
if(prime(a + 2)) cout << "3\n" << a << ' ' << a + 2 << ' ' << b << endl;
else if(prime(a - 2)) cout << "3\n" << a << ' ' << a - 2 << ' ' << b << endl;
else cout << -1 << endl;
return;
}
if(prime(a + 2) && prime(b + 2)){
cout << "5\n" << a << ' ' << a + 2 << " 2 " << b + 2 << ' ' << b << endl;
}
else if(prime(a - 2) && prime(b - 2)){
cout << "3\n" << a << " 2 " << b << endl;
}
else if(prime(a - 2) && prime(b + 2)){
cout << "4\n" << a << " 2 " << b + 2 << ' ' << b << endl;
}
else if(prime(a + 2) && prime(b - 2)){
cout << "4\n" << a << ' ' << a + 2 << " 2 " << b << endl;
}
else cout << -1 << endl;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
292 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
296 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
121 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |