Cod sursa(job #1458522)

Utilizator roadtojediWilly Fog roadtojedi Data 7 iulie 2015 18:23:30
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.69 kb
//Eratostene

#include <iostream>
#include <fstream>
#include <bitset>
using namespace std;

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

const int MAX_N = 2000002;
bitset<MAX_N> viz;

void ciur(int n)
{

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

}


int main()
{
    int n;
    f >>n;
    ciur(n);
    if(n >= 2)
    {
        int nr = 1;
        for(int i = 3; i <= n; i+=2)
        {
            if(viz[i] == 0)
            {
                nr++;
            }
        }
        g<<nr;
    }

}