Cod sursa(job #2190993)

Utilizator Narvik13Razvan Roatis Narvik13 Data 1 aprilie 2018 11:51:13
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <iostream>
#include <fstream>
#include <bitset>
#define NMAX 2000002

using namespace std;

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

int n;
bitset <NMAX> viz;

int ciur()
{
    int total = 1;

    for(int i = 3; i <= n; i += 2)
        if(not viz.test(i))
        {
            total ++;
            for(int j = i << 1; j <= n; j += i)
                viz.set(j);
        }

    return total;
}

int main()
{
    f >> n;
    o << ciur();
    return 0;
}