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<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
using namespace std;
typedef long long ll;
int add(int a, int b)
{
ll x = a+b;
if(x >= mod)
x -= mod;
if(x < 0)
x += mod;
return x;
}
ll mul(ll a, ll b)
{
return (a*b) % mod;
}
ll pw(ll a, ll b)
{
ll ans = 1;
while(b)
{
if(b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
ll a, b;
bool prim(ll a)
{
if(a <= 1)
return 0;
for(ll i = 2; i * i <= a; ++i)
if(a % i == 0)
return 0;
return 1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> a >> b;
if(prim(abs(a - b)))
{
cout << 2 << '\n';
cout << a << " " << b << '\n';
return 0;
}
if(b == 2)
{
if(prim(a + 2))
{
cout << 3 << '\n';
cout << a << " " << a+2 << " " << b << '\n';
return 0;
}
if(prim(a - 2))
{
cout << 3 << '\n';
cout << a << " " << a-2 << " " << b << '\n';
return 0;
}
cout << -1;
return 0;
}
if(a == 2)
{
if(prim(b + 2))
{
cout << 3 << '\n';
cout << a << " " << b+2 << " " << b << '\n';
return 0;
}
if(prim(b - 2))
{
cout << 3 << '\n';
cout << a << " " << b-2 << " " << b << '\n';
return 0;
}
cout << -1;
return 0;
}
if(prim(a - 2) && prim(b - 2))
{
cout << 3 << '\n';
cout << a << " " << 2 << " " << b << '\n';
return 0;
}
if(prim(a + 2) && prim(b - 2))
{
cout << 4 << '\n';
cout << a << " " << a + 2 << " " << 2 << " " << b << '\n';
return 0;
}
if(prim(a - 2) && prim(b + 2))
{
cout << 4 << '\n';
cout << a << " " << 2 << " " << b + 2 << " " << b << '\n';
return 0;
}
if(prim(a + 2) && prim(b + 2))
{
cout << 5 << '\n';
cout << a << " " << a + 2 << " " << 2 << " " << b + 2 << " " << b << '\n';
return 0;
}
cout << -1;
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... |