P5736 【深基7.例2】质数筛

题目传送门

#include <bits/stdc++.h>

using namespace std;

const int N = 110;
int a[N];

bool isPrime(int n) {
    if (n < 2) return false;
    for (int i = 2; i <= n / i; i++)
        if (n % i == 0)return false;
    return true;
}

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++)
        if (isPrime(a[i]))
            cout << a[i] << " ";

    return 0;
}
原文地址:https://www.cnblogs.com/littlehb/p/15575528.html