# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198429 | leonarda | Lutrija (COCI19_lutrija) | C++14 | 459 ms | 504 KiB |
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>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pi;
typedef long long int lint;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef set<int> si;
const int inf = 0x3f3f3f3f;
const int maxn = 0;
const int MOD = 1e9 + 7;
lint a, b;
vector<lint> v;
vector<lint> ans;
bool isPrime (lint t)
{
if(t == 0 or t == 1)
return 0;
for(lint i = 2; i <= sqrt(t); ++i)
if(t % i == 0)
return 0;
return 1;
}
bool check (vector<lint> t)
{
if(!isPrime(abs(a - t[0])))
return 0;
for(int i = 0; i < t.size() - 1; ++i)
if(!isPrime(abs(t[i] - t[i + 1])))
return 0;
if(!isPrime(abs(t[t.size() - 1] - b)))
return 0;
return 1;
}
bool fuki (int x)
{
vector<lint> t;
int i = 0;
while(x)
{
if(x % 2 == 1)
t.pb(v[i]);
x /= 2;
++i;
}
sort(t.begin(), t.end());
do
{
if(check(t))
{
ans.pb(a);
for(int i = 0; i < t.size(); ++i)
ans.pb(t[i]);
ans.pb(b);
return 1;
}
} while(next_permutation(t.begin(), t.end()));
return 0;
}
bool solve (void)
{
if(v.empty())
return 0;
for(int i = 1; i < pow(2, v.size()); ++i)
if(fuki(i))
return 1;
return 0;
}
int main ()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> a >> b;
if(isPrime(abs(a - b)))
return cout << 2 << endl << a << " " << b, 0;
if(a != 2 and b != 2)
{
if(isPrime(a - 2))
v.pb(a - 2);
if(isPrime(a + 2))
v.pb(a + 2);
if(isPrime(b - 2))
v.pb(b - 2);
if(isPrime(b + 2))
v.pb(b + 2);
v.pb(2);
if(solve())
{
cout << ans.size() << endl;
for(int i = 0; i < ans.size(); ++i)
cout << ans[i] << " ";
} else
cout << -1;
} else {
if(a == 2)
{
if(isPrime(b - 2))
v.pb(b - 2);
if(isPrime(b + 2))
v.pb(b + 2);
}
if(b == 2)
{
if(isPrime(a - 2))
v.pb(a - 2);
if(isPrime(a + 2))
v.pb(a + 2);
}
if(solve())
{
cout << ans.size() << endl;
for(int i = 0; i < ans.size(); ++i)
cout << ans[i] << " ";
} else
cout << -1;
}
return 0;
}
Compilation message (stderr)
# | 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... |