#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(int 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(abs(b - a) == 2)
{
cout << 2 << endl;
cout << a << " " << b << endl;
}
else if(a % 2 == 1 && b % 2 == 1)
{
bool g = 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
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;
ll y = b;
if(a % 2 == 0)
swap(a, b);
if(chk(a + 2))
mn.pb(a + 2);
if(chk(a - 2)){
mn.pb(a - 2);
mn.pb(2);
}
bool g = 0;
for(int i = 0;i < mn.sz();i++)
{
if(chk(abs(mn[i] - b)) == 1)
{
cout << 3 << endl;
cout << x << " " << mn[i] << " " << y << endl;
g = 1;
break;
}
}
if(g == 0)
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:57:14: warning: unused variable 'g' [-Wunused-variable]
57 | bool g = 0;
| ^
lutrija.cpp:93:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for(int i = 0;i < mn.sz();i++)
| ~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |