Cod sursa(job #2640584)

Utilizator robeert.77Chirica Robert robeert.77 Data 6 august 2020 22:52:22
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <fstream>
using namespace std;

ifstream fin ("ciur.in");
ofstream fout ("ciur.out");

int main() {
    fin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    fin >> n;

    bool isNotPrime[n + 1] = {false};
    for (int i = 2; i * i <= n; i++)
        if (!isNotPrime[i])
            for (int j = i * i; j <= n; j += i)
                isNotPrime[j] = true;

    int nr = 0;
    for (int i = 2; i <= n; i++)
        if (!isNotPrime[i])
            nr++;
    fout << nr;

    return 0;
}