Cod sursa(job #2778410)

Utilizator Theodor17Pirnog Theodor Ioan Theodor17 Data 1 octombrie 2021 12:46:52
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <fstream>
#include <bitset>
#define limit 2000000

using namespace std;

ifstream cin("ciur.in");
ofstream cout("ciur.out");

bitset <limit + 1> c;
int nr_prime, n;

void eratostene(){

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

    for(int i = 2; i <= n; i++)
        if(!c[i])
            nr_prime++;

    cout << nr_prime;
}   

int main(){

    cin >> n;
    eratostene();

}