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>
#define f first
#define s second
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define ld long double
using namespace std;
void data() {
#ifdef NURS
freopen("main.in", "r", stdin);
freopen("main.out", "w", stdout);
#endif
}
void win()
{
ios_base::sync_with_stdio(0),
cin.tie(0),cout.tie(0);
}
int block = 400;
const ld eps = 1e-6;
const int N = 1e6 + 500;
const int mod = 1e9 + 7;
const ll hh = 100010683;
const ll hh2 = 150005819;
ll a, b, pos, pos2;
bool check(ll x)
{
for (int j = 2; j <= sqrt(x); j++)
{
if (x % j == 0)
return 0;
}
return 1;
}
bool got, was[200];
vector<int> g[200];
int par[200];
void dfs(int v)
{
// cout << v << '\n';
if (v == pos)
got = 1;
was[v] = 1;
for (int i = 0; i < g[v].size(); i++)
{
int to = g[v][i];
if (was[to] == 0)
{
dfs(to), par[to] = v;
}
}
}
int main()
{
data();
win();
cin >> a >> b;
vector<ll> v;
map<ll, bool> was;
for (ll i = a - 2; i <= a + 2; i++)
{
if (check(i) && was[i] == 0 && i > 1)
v.pb(i), was[i] = 1;
}
for (ll i = b - 2; i <= b + 2; i++)
{
if (check(i) && was[i] == 0 && i > 1)
v.pb(i), was[i] = 1;;
}
sort(all(v));
pos = -1, pos2 = 1000;;
for (int i = 0; i < v.size(); i++)
{
for (int j = 0; j < v.size(); j++)
{
ll k = abs(v[i] - v[j]);
if (check(k))
g[i].pb(j);
}
}
for (int i = 0; i < v.size(); i++)
{
if (v[i] == b)
pos = i;
if (v[i] == a)
pos2 = i;
}
par[pos2] = -1;
dfs(pos2);
if (got)
{
vector<int> ans;
b = pos;
while (par[b] != -1)
{
ans.pb(v[b]), b = par[b];
}
ans.pb(v[b]);
reverse(all(ans));
cout << ans.size() << '\n';
for (int i = 0; i < ans.size(); i++)
{
cout << ans[i] << " ";
}
return 0;
}
cout << -1;
}
Compilation message (stderr)
lutrija.cpp: In function 'void dfs(int)':
lutrija.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i = 0; i < g[v].size(); i++)
| ~~^~~~~~~~~~~~~
lutrija.cpp: In function 'int main()':
lutrija.cpp:80:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
lutrija.cpp:82:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for (int j = 0; j < v.size(); j++)
| ~~^~~~~~~~~~
lutrija.cpp:89:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
lutrija.cpp:109:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for (int i = 0; i < ans.size(); i++)
| ~~^~~~~~~~~~~~
# | 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... |