#include <random>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#define fr first
#define sc second
#define ad push_back
using namespace std;
using ll = long long;
mt19937 rnd(348502);
const ll N = 100005;
bool is_prime(ll a)
{
if (a < 2)
return 0;
for (ll i = 2; i * i <= a; i++)
{
if (a % i == 0)
return 0;
}
return 1;
}
void solve()
{
ll a, b;
cin >> a >> b;
if (is_prime(abs(a - b)))
{
cout << 2 << '\n' << a << ' ' << b;
}
else if (a == 2)
{
if (is_prime(b + 2))
cout << 3 << '\n' << 2 << ' ' << b + 2 << ' ' << b;
else
cout << -1;
}
else if (b == 2)
{
if (is_prime(a + 2))
cout << 3 << '\n' << a << ' ' << a + 2 << ' ' << 2;
else
cout << -1;
}
else if (is_prime(a - 2) && is_prime(b - 2))
{
cout << 3 << '\n' << a << ' ' << 2 << ' ' << b;
}
else if (is_prime(a + 2) && is_prime(b + 2))
{
cout << 5 << '\n' << a << ' ' << a + 2 << ' ' << 2 << ' ' << b + 2 << ' ' << b;
}
else if (is_prime(a + 2) && is_prime(b - 2))
{
cout << 4 << '\n' << a << ' ' << a + 2 << ' ' << 2 << ' ' << b;
}
else if(is_prime(a - 2) && is_prime(b + 2))
{
cout << 4 << '\n' << a << ' ' << 2 << ' ' << b + 2 << ' ' << b;
}
else
cout << -1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
500 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
126 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
436 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
592 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |