This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |