#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define pii pair<ll, ll>
using namespace std;
const ll MAX = 1e14;
ll a, b;
bool isPrime(ll n){
if(n <= 1) return false;
for (int i = 2; 1ll * i * i <= n; i++)
{
if(n % i == 0){
return false;
}
}
return true;
}
vector<ll> ans;
void f(ll n){
if(n == 2){
if(isPrime(b - 2)){
ans.push_back(b);
}
else if(b + 2 <= MAX && isPrime(b + 2)){
ans.push_back(b + 2);
ans.push_back(b);
}
else{
ans.clear();
}
return;
}
if(isPrime(n - 2)){
ans.push_back(2);
f(2);
}
else if(n + 2 <= MAX && isPrime(n + 2)){
ans.push_back(n + 2);
f(n + 2);
}
else{
ans.clear();
}
}
int main(){
cin >> a >> b;
ans.push_back(a);
f(a);
if(ans.size() == 0){
cout << -1 << '\n';
}
else{
cout << ans.size() << '\n';
for(ll a:ans){
cout << a << ' ';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 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 |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
215 ms |
276 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
267 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
193 ms |
284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
242 ms |
288 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
174 ms |
276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
280 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
61 ms |
212 KB |
Output is correct |