Cod sursa(job #2717528)

Utilizator IoanaDraganescuIoana Draganescu IoanaDraganescu Data 7 martie 2021 15:50:17
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int NMax = 2 * 1e6;

int n, ans;
bool sieve[NMax + 5];

void Read(){
    fin >> n;
}

void Eratosthenes(){
    for (int i = 2; i <= n; i++)
        if (!sieve[i]){
            ans++;
            for (int j = 2 * i; j <= n; j += i)
                sieve[j] = 1;
        }
}

void Print(){
    fout << ans << '\n';
}

int main(){
    Read();
    Eratosthenes();
    Print();
    return 0;
}