Cod sursa(job #2531439)

Utilizator andreiomd1Onut Andrei andreiomd1 Data 26 ianuarie 2020 12:04:00
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

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

const int NMAX = 2e6 + 5;

int N;

bool Sel[NMAX];

static inline void Eratosthenes (int N)
{
    Sel[0] = Sel[1] = 1;

    for(int i = 4; i <= N; i += 2)
        Sel[i] = 1;

    for(int i = 3; i * i <= N; i += 2)
        if(!Sel[i])
            for(int j = 3; j * i <= N; j += 2)
                Sel[i * j] = 1;

    return;
}

int main ()
{
    f.tie(NULL);

    f >> N;

    Eratosthenes(N);

    int ans = 0;

    for(int i = 2; i <= N; ++i)
        if(Sel[i])
            continue;
        else ++ans;

    g << ans << '\n';

    return 0;
}