#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
bool is_prime(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;
}
bool solve(vector<long long> t)
{
for(auto v:t)
{
if(!is_prime(v))
return false;
}
for(size_t i=1;i<t.size();i++)
{
if(!is_prime(abs(t[i]-t[i-1])))
return false;
}
cout<<t.size()<<"\n";
for(auto v:t)
cout<<v<<" ";
cout<<"\n";
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long a,b;
cin>>a>>b;
if(a==2)
{
if(solve({a,b-2,b}))
return 0;
if(solve({a,b+2,b}))
return 0;
cout<<"-1\n";
return 0;
}
else if(b==2)
{
if(solve({a,a-2,b}))
return 0;
if(solve({a,a+2,b}))
return 0;
cout<<"-1\n";
return 0;
}
else
{
if(solve({a,2,b}))
return 0;
if(abs(b-a)<=30)
{
vector<long long> tmp;
if(a<b)
{
for(long long i=a;i<=b;i+=2)
tmp.push_back(i);
}
else
{
for(long long i=a;i>=b;i-=2)
tmp.push_back(i);
}
if(solve(tmp))
return 0;
}
cout<<"-1\n";
return 0;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
159 ms |
284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
158 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
175 ms |
288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
127 ms |
284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |