# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
735877 | aykhn | Lutrija (COCI19_lutrija) | C++14 | 293 ms | 304 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>
/*
author: aykhn
5/4/2023
*/
using namespace std;
typedef long long ll;
const int oo = INT_MAX;
const ll ooo = LONG_MAX;
const ll mod = 1e9 + 7;
#define OPT ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define tos to_string
#define infll 0x3F3F3F3F3F3F3F3FLL
#define bpc __builtin_popcount
bool isPrime(ll a)
{
if (a <= 1) return false;
for (ll i = 2; i * i <= a; i++)
{
if (a % i == 0) return false;
}
return true;
}
ll a, b, n;
vector<ll> v;
bool check(vector<ll> &arr)
{
ll l = arr.size();
if (!l) return isPrime(abs(a - b));
if (!isPrime(abs(arr[0] - a)) || !isPrime(abs(arr[l - 1] - b))) return false;
for (ll i = 1; i < l; i++)
{
if (!isPrime(abs(arr[i] - arr[i - 1]))) return false;
}
return true;
}
bool f(vector<ll> arr, vector<ll> used)
{
bool flag = 0;
for (ll i = 0; i < n; i++)
{
if (used[i]) continue;
flag = 1;
used[i] = 1;
arr.pb(v[i]);
if (f(arr, used)) return true;
arr.pop_back();
if (f(arr, used)) return true;
used[i] = 0;
}
if (!flag)
{
if (check(arr))
{
cout << arr.size() + 2 << endl;
cout << a << " ";
for (ll i = 0; i < arr.size(); i++) cout << arr[i] << " ";
cout << b << endl;
return true;
}
return false;
}
}
int main()
{
cin >> a >> b;
if (a != 2 && b != 2) v.pb(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);
n = v.size();
vector<ll> used(n, 0);
vector<ll> arr;
if (!f(arr, used))
{
cout << -1 << endl;
}
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... |