| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1370236 | eyadooz | Lutrija (COCI19_lutrija) | C++20 | 46 ms | 432 KiB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define endl '\n'
#define int long long
bool prime(int x) {
for(int i=2;i*i<=x;i++) {
if(x%i==0) return 0;
}
return 1;
}
main()
{
cin.tie(0) -> sync_with_stdio(0);
int a, b;
cin >> a >> b;
if(prime(abs(b-a))) {cout << "2\n" << a << " " << b << endl;return 0;}
bool swp=0;
int orgb=b, oa, ob;
if(a>b) {swap(a, b);swp=1;}
oa=a, ob=b;
if(a==2) {
vector<int> ans;
if(prime(b-a)) {
ans.pb(a);
ans.pb(b);
}
else if(prime(b+2)) {
ans.pb(a);
ans.pb(b+2);
ans.pb(b);
}
if(swp) reverse(all(ans));
if(sz(ans)==0) {cout << -1 << endl;return 0;}
cout << sz(ans) << endl;
for(auto i : ans) cout << i << " ";
}
else {
vector<int> ans;
bool valid=1;
ans.pb(a);
while(a<b&&sz(ans)<=30) {
a+=2;
if(!prime(a)) valid=0;
ans.pb(a);
if(prime(a-2)) {
vector<int> rans=ans;
bool invalid=1;
if(prime(b-2)) {
rans.pb(2);
rans.pb(b);
}
else if(prime(b+2)) {
rans.pb(2);
rans.pb(b+2);
rans.pb(b);
}
else invalid=0;
if(sz(rans)==0||!invalid||sz(rans)>30) {cout << -1 << endl;return 0;}
if(swp) reverse(all(rans));
cout << sz(rans) << endl;
for(auto i : rans) cout << i << " ";
return 0;
}
}
cout << -1;
return 0;
// if(swp) reverse(all(ans));
// if(ans.back()!=orgb||!valid||sz(ans)>30) {
// ans.clear();
// a=oa, b=ob;
// ans.pb(a);
// valid=1;
// while(a>2&&sz(ans)<=30) {
// if(!prime(a)) {valid=0;break;}
// if(prime(a-2)) break;
// a-=2;
// ans.pb(a);
// }
// if(!prime(abs(a-2))||!valid) {cout << -1 << endl;return 0;}
// a=2;
// if(prime(b-a)) {
// ans.pb(a);
// ans.pb(b);
// }
// else if(prime(b+2)) {
// ans.pb(a);
// ans.pb(b+2);
// ans.pb(b);
// }
// else valid=0;
// if(swp) reverse(all(ans));
// if(sz(ans)==0||!valid||sz(ans)>30) {cout << -1 << endl;return 0;}
// cout << sz(ans) << endl;
// for(auto i : ans) cout << i << " ";
// return 0;
// }
// cout << sz(ans) << endl;
// for(auto i : ans) cout << i << " ";
}
}
Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
