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 int long long
#define pb push_back
using namespace std;
const int N=1e6,M=2e3,mod=1e9+7;
map<int,int>dist,p;
map<int,vector<int>>adj;
main(){
int a,b;
cin>>a>>b;
vector<int>v;
v.pb(a);
v.pb(b);
v.pb(a-2);
v.pb(a+2);
v.pb(b+2);
v.pb(b-2);
v.pb(2);
for(int i=0;i<v.size();i++){
for(int j=0;j<v.size();j++){
if(j==i||v[i]==v[j])
continue;
int ok1=0;
for(int k=2;k*k<=v[i];k++){
if(v[i]%k==0)
ok1=1;
}
if(ok1==1)
continue;
ok1=0;
for(int k=2;k*k<=v[j];k++){
if(v[j]%k==0)
ok1=1;
}
if(ok1==1)
continue;
int x=abs(v[i]-v[j]);
if(x==1)
continue;
int ok=0;
for(int k=2;k*k<=x;k++){
if(x%k==0)
ok=1;
}
if(ok==0)
adj[v[i]].pb(v[j]);
}
}
for(int i=0;i<v.size();i++){
for(int j=0;j<adj[v[i]].size();j++)
cout<<adj[v[i]][j]<<" ";
cout<<endl;
}
queue<int>q;
dist[a]=1;
q.push(a);
while(!q.empty()){
int node=q.front();
q.pop();
for(auto x:adj[node]){
if(!dist[x])
q.push(x),dist[x]=1,p[x]=node;
}
}
if(dist[b]==0)
cout<<"-1"<<endl;
else{
int node=b;
vector<int>ans;
while(p[node]!=a)
ans.pb(node),node=p[node];
reverse(ans.begin(),ans.end());
ans.pb(a);
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<" ";
}
cout<<endl;
}
return 0;
}
Compilation message (stderr)
lutrija.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main(){
| ^~~~
lutrija.cpp: In function 'int main()':
lutrija.cpp:26:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
lutrija.cpp:27:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int j=0;j<v.size();j++){
| ~^~~~~~~~~
lutrija.cpp:67:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
lutrija.cpp:68:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int j=0;j<adj[v[i]].size();j++)
| ~^~~~~~~~~~~~~~~~~
lutrija.cpp:105:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | 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... |