Submission

Status:

PPPPPP-PP-

Subtask/Task Score:

80/100

Score: 80

User: scoobydoobydoo

Problemset: จำนวนเฉพาะ (2560)

Language: cpp

Time: 0.003 second

Submitted On: 2026-10-15 15:05:27

#include <iostream>
using namespace std;
#define ll long long
#define el << '\n'

bool isPrime (int x) {
    if (x < 2) return false;

    for (int i=2; i*i <= x; i++) {
        if(x % i == 0) return false;
    }
    return true;
}

int main() {

    int n;
    cin >> n;

    cout << 2 el;
    for (int i=3; i<=n; i+=2) {
        if (isPrime(i)) {
            cout << i el;
        }
    }

    return 0;
}