# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
228478 |
2020-05-01T07:16:38 Z |
grt |
Lutrija (COCI19_lutrija) |
C++17 |
|
335 ms |
432 KB |
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
ll a,b;
bool swapped;
bool is_prime(ll x) {
if(x == 0) return 0;
for(ll i = 2; i * i <= x; ++i) {
if(x % i == 0) return 0;
}
return 1;
}
int main() {_
cin >> a >> b;
if(a > b) {
swap(a,b);
swapped = 1;
}
bool ok = 0;
for(ll i = a; i <= b; i+=2) {
if(!is_prime(i)) {
break;
}
if(i == b) ok = 1;
}
vector<ll>ans = {};
if(ok) {
for(ll i = a; i <= b; i+=2) {
ans.PB(i);
}
} else {
ans.PB(a);
bool jump = (a == 2);
if(!jump && is_prime(a-2)) {
jump = 1;
ans.PB(2);
} else if(is_prime(a+2)) {
jump = 1;
ans.PB(a+2);
ans.PB(2);
}
if(!jump) {
cout << "-1";
return 0;
}
jump = 0;
if(is_prime(b - 2)) {
ans.PB(b);
jump = 1;
} else if(is_prime(b+2)) {
ans.PB(b+2);
ans.PB(b);
jump = 1;
}
if(!jump) {
cout << "-1";
return 0;
}
}
cout << (int)ans.size() << "\n";
if(swapped) reverse(ans.begin(),ans.end());
for(auto x : ans) {
cout << x << " ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
432 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
310 ms |
388 KB |
Output is correct |
2 |
Correct |
47 ms |
384 KB |
Output is correct |
3 |
Correct |
196 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
314 ms |
384 KB |
Output is correct |
2 |
Correct |
20 ms |
384 KB |
Output is correct |
3 |
Correct |
145 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
335 ms |
384 KB |
Output is correct |
2 |
Correct |
77 ms |
384 KB |
Output is correct |
3 |
Correct |
133 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
384 KB |
Output is correct |
2 |
Correct |
37 ms |
384 KB |
Output is correct |
3 |
Correct |
49 ms |
384 KB |
Output is correct |