Cod sursa(job #2564922)

Utilizator NotTheBatmanBruce Wayne NotTheBatman Data 2 martie 2020 11:05:07
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>
#include <bitset>

using namespace std;

const int N = 2e6 + 5;

bitset <N> sieve;
int n;

void Create_Sieve (int x)
{
    for (int i = 4; i <= x; i += 2)
        sieve[i] = 1;
    for (int i = 3; i * i <= x; i += 2)
        if (!sieve[i])
            for (int j = i * i; j <= x; j += 2 * i)
                sieve[j] = 1;
}

void Read ()
{
    ifstream fin ("ciur.in");
    ofstream fout ("ciur.out");
    fin >> n;
    Create_Sieve(n);
    int ans = 1;
    for (int i = 3; i <= n; i += 2)
        if (!sieve[i]) ans++;
    fout << ans << "\n";
}


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