Submission

Status:

PPPPPPPPPPPPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: helloskibidi

Problemset: จำนวนเฉพาะก่อนหน้า

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-06 11:16:11

#include <bits/stdc++.h>
using namespace std;

bool isPrime(int x){
    if(x < 2) return false;
    if(x < 4) return true;
    if(x % 2 == 0 || x % 3 == 0) return false;
    for(int d = 5; (long long)d * d <= x; d += 6){
        if(x % d == 0 || x % (d + 2) == 0) return false;
    }
    return true;
}

int main(){
    int n; cin >> n;

    vector<int> x;
    for(int i = n - 1; i >= 2 && x.size() < 5; i--){
        if(isPrime(i)){
            x.push_back(i);
        }
    }
    sort(x.begin() , x.end());
    for(int p : x) cout << p << ' ';
    cout << '\n';
}