# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
251536 | MrRobot_28 | Lutrija (COCI19_lutrija) | C++17 | 514 ms | 384 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 int long long
const int N = 10;
vector <bool> used(N);
vector <int> v, tmp, ans;
int a, b;
bool prost(int x)
{
if(x < 2)
{
return 0;
}
for(int j = 2; j * j <= x; j++)
{
if(x % j == 0)
{
return 0;
}
}
return 1;
}
void dfs(int x)
{
used[x] = true;
tmp.push_back(v[x]);
if(v[x] == b){
if(ans.size() == 0 || ans.size() > tmp.size())
{
ans = tmp;
}
tmp.pop_back();
return;
}
for(int i = 0; i < v.size(); i++)
{
if(!used[i] && prost(abs(v[x] - v[i])))
{
dfs(i);
used[i] = 0;
}
}
tmp.pop_back();
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> a >> b;
for(int i = a - 2; i <= a + 2; i++)
{
if(prost(i))
{
v.push_back(i);
}
}
for(int i = b - 2; i <= b + 2; i++)
{
if(prost(i))
{
v.push_back(i);
}
}
v.push_back(2);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for(int i = 0; i < v.size(); i++)
{
if(v[i] == a)
{
dfs(i);
}
}
if(ans.size() == 0)
{
cout << -1;
}
else
{
cout << ans.size() << "\n";
for(int i = 0; i < ans.size(); i++)
{
cout << ans[i] << " ";
}
}
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... |