# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199481 | SamAnd | Lutrija (COCI19_lutrija) | C++17 | 407 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;
long long a, b;
bool stgg(long long x)
{
if (x <= 1)
return false;
for (long long i = 2; i * i <= x; ++i)
{
if (x % i == 0)
return false;
}
return true;
}
vector<long long> v;
bool c[7][7];
vector<long long> ans;
bool cc[7];
bool dfs(int i)
{
if (cc[i])
return false;
cc[i] = true;
ans.push_back(v[i]);
if (v[i] == b && ans.size() > 1)
return true;
for (int j = 0; j < v.size(); ++j)
{
if (c[i][j])
{
if (dfs(j))
return true;
}
}
ans.pop_back();
return false;
}
int main()
{
scanf("%lld%lld", &a, &b);
if (a == 2 && b == 2)
{
printf("3\n2 5 2\n");
return 0;
}
if (stgg(a - 2))
v.push_back(a - 2);
v.push_back(a);
if (stgg(a + 2))
v.push_back(a + 2);
if (stgg(b - 2))
v.push_back(b - 2);
v.push_back(b);
if (stgg(b + 2))
v.push_back(b + 2);
v.push_back(2);
for (int i = 0; i < v.size(); ++i)
{
for (int j = i + 1; j < v.size(); ++j)
{
if (stgg(abs(v[i] - v[j])))
{
c[i][j] = c[j][i] = true;
}
}
}
for (int i = 0; i < v.size(); ++i)
{
if (v[i] == a)
{
if (dfs(i))
{
printf("%d\n", ans.size());
for (int i = 0; i < ans.size(); ++i)
printf("%lld ", ans[i]);
printf("\n");
return 0;
}
printf("-1\n");
return 0;
}
}
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... |