#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
ll A, B;
bool is_prime(ll x) {
if (x <= 1) return 0;
FOR (i, 2, sqrt(x)) if (x % i == 0) return 0;
return 1;
}
void solve() {
cin >> A >> B;
if (is_prime(abs(A - B))) {
cout << "2\n";
cout << A << ' ' << B << '\n';
return;
}
vector<ll> ans;
ans.pb(A);
if (A != 2) {
bool f = 0;
for (ll x : {A - 2, A, A + 2}) if (is_prime(x) && is_prime(abs(x - 2))) {
if (x != A) ans.pb(x);
f = 1;
break;
}
if (!f) {
cout << "-1\n";
return;
}
}
if (A != 2 && B != 2) ans.pb(2);
if (B != 2) {
bool f = 0;
for (ll x : {B - 2, B, B + 2}) if (is_prime(x) && is_prime(abs(x - 2))) {
if (x != B) ans.pb(x);
f = 1;
break;
}
if (!f) {
cout << "-1\n";
return;
}
}
ans.pb(B);
cout << ans.size() << '\n';
for (ll x : ans) cout << x << ' ';
cout << '\n';
}
int main() {
Waimai;
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
416 ms |
296 KB |
Output is correct |
2 |
Correct |
41 ms |
216 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
401 ms |
292 KB |
Output is correct |
2 |
Correct |
13 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
454 ms |
292 KB |
Output is correct |
2 |
Correct |
63 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
328 ms |
212 KB |
Output is correct |
2 |
Correct |
29 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |