Cod sursa(job #2692803)

Utilizator SerbaP123Popescu Serban SerbaP123 Data 3 ianuarie 2021 19:50:27
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>
#include <bitset>
#define nmax 2000000
using namespace std;

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

bitset <nmax + 1> seive;

int main(){
    int limit, countPrimeNumber = 0;
    seive[0] = seive[1] = true;
    cin >> limit;
    for(int i = 4; i <= limit; i += 2){
        seive[i] = true;
    }
    for(int i = 3; i * i <= limit; i += 2){
        if(!seive[i]){
            for(int j = i * i; j <= limit; j += 2 * i){
                seive[j] = true;
            }
        }
    }
    for(int i = 2; i <= limit; ++i){
        if(!seive[i]){
            countPrimeNumber++;
        }
    }
    cout << countPrimeNumber;
    return 0;
}