제출 #1370219

#제출 시각아이디문제언어결과실행 시간메모리
1370219eyadoozLutrija (COCI19_lutrija)C++20
14 / 70
111 ms432 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);
        }
        else if(b-2>1&&prime(b-2)&&prime(abs(b-4))) {
            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(swp) reverse(all(ans));
        if(ans.back()!=orgb||!valid||sz(ans)>30) {
            ans.clear();
            a=oa, b=ob;
            ans.pb(a);
            if(!prime(abs(a-2))) {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 if(b-2>1&&prime(b-2)&&prime(abs(b-4))) {
                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 << " ";
            return 0;
        }
        cout << sz(ans) << endl;
        for(auto i : ans) cout << i << " ";
    }
}

컴파일 시 표준 에러 (stderr) 메시지

lutrija.cpp:20:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   20 | main()
      | ^~~~
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…