Cod sursa(job #2851053)

Utilizator VladTZYVlad Tiganila VladTZY Data 17 februarie 2022 23:16:00
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <fstream>

#define NMAX 2000005

using namespace std;

ifstream f("ciur.in");
ofstream g("ciur.out");

int n, nrPrimes;
bool ciur[NMAX];

void getPrimes(int n) {

    ciur[0] = true;
    ciur[1] = true;

    for (int i = 2; i <= n; i++) {

        if (!ciur[i]) {

            nrPrimes++;

            for (int j = i; 1ll * j * i <= n; j++)
                ciur[i * j] = true;
        }
    }
}

int main()
{
    f >> n;

    getPrimes(n);

    g << nrPrimes << "\n";

    return 0;
}