#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
241 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
277 ms |
380 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
231 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |