Cod sursa(job #2669195)

Utilizator bogdan2604Bogdan Dumitrescu bogdan2604 Data 6 noiembrie 2020 13:56:06
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.54 kb
#include <fstream>
#include <bitset>

using namespace std;

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

int n,k,i,j;
bitset <2000001> prim;

void eratostene()
{
    prim[1] = 1;
    for(i = 4; i <= n; i += 2)
        prim[i] = 1;
    for(i = 3; i * i <= n; i += 2)
    {
        j = 3;
        while(i * j <= n)
        {
            prim[i * j] = 1;
            j += 2;
        }
    }
}

int main()
{
    f >> n;
    eratostene();
    for(i = 1; i <= n; ++ i)
        if(!prim[i])
        ++ k;
    g << k;
}