| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1370235 | eyadooz | Lutrija (COCI19_lutrija) | C++20 | 67 ms | 452 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;
}
}
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 << " ";
}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
