#include "bits/stdc++.h"
#define pb(x) push_back(x)
#define fil(x, y) memset(x, y, sizeof(x))
#define ll long long
#define ff first
#define ss second
#define printp(x) x.ff << " " << x.ss
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mp(x, y) make_pair(x,y)
#define inf 1073741823
#define infll 4611686018427387903
#define M 1000000007
#define db(x) cout << x << " ";
#define N 10000007
#define sz size
#define sm 0.0000007
#define ins insert
#define ers erase
#define all(k) k.begin(), k.end()
#define cnt count
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;
bool chk(ll n)
{
ll sqrtn = sqrt(n + 1) + 1;
bool g = 0;
for(ll i = 2;i <= sqrtn && i < n;i++)
{
if(n % i == 0)
{
return 0;
}
}
return 1;
}
int main()
{
fastio;
ll a, b;
cin >> a >> b;
if(a == 2 && b == 2)
{
cout << 3 << endl;
cout << 2 << " " << 5 << " " << 2 << endl;
}
else if(a % 2 == 1 && b % 2 == 1)
{
if(abs(b - a) == 2)
{
cout << 2 << endl;
cout << a << " " << b << endl;
return 0;
}
if(chk(a - 2) == 1 && (chk(b - 2) == 1))
{
cout << 3 << endl;
cout << a << " " << 2 << " " << b << endl;
}
else if(chk(a - 2) == 1 && chk(b + 2) == 1)
{
cout << 4 << endl;
cout << a << " " << 2 << " " << b + 2 << " " << b << endl;
}
else if(chk(a + 2) == 1 && chk(b - 2) == 1)
{
cout << 4 << endl;
cout << a << " " << a + 2 << " " << 2 << " " << b << endl;
}
else if(chk(a + 2) == 1 && chk(b + 2) == 1)
{
cout << 5 << endl;
cout << a << " " << a + 2 << " " << 2 << " " << b + 2 << " " << b << endl;
}
else
cout << -1 << endl;
}
else
{
ll n = abs(b - a);
if(chk(n) == 1)
{
cout << 2 << endl;
cout << a << " " << b << endl;
}
else
{
vector <ll> mn;
ll x = a, y = b;
if(a % 2 == 0)
swap(a, b);
if(chk(a + 2) == 1)
{
cout << 3 << endl;
if(a == x)
{
cout << a << " " << a + 2 << " " << 2 << endl;
}
else
{
cout << 2 << " " << a + 2 << " " << a << endl;
}
}
else
cout << -1 << endl;
}
}
return 0;
}
Compilation message
lutrija.cpp: In function 'bool chk(long long int)':
lutrija.cpp:30:10: warning: unused variable 'g' [-Wunused-variable]
30 | bool g = 0;
| ^
lutrija.cpp: In function 'int main()':
lutrija.cpp:92:23: warning: unused variable 'y' [-Wunused-variable]
92 | ll x = a, y = b;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
235 ms |
292 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
284 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
267 ms |
288 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |