Cod sursa(job #1754854)

Utilizator lucian666Vasilut Lucian lucian666 Data 8 septembrie 2016 20:23:38
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb


#include <iostream>
#include <fstream>
#include <bitset>

using namespace std;
#define dim 2000009
ofstream out("ciur.out");

int n;
int sol[dim];
bitset<dim> uz;

void ciur()
{
    uz[1] = 1;
    for(int i = 2 ; i<=dim; ++i)
    {
        if(!uz[i])
        {
            sol[i] = 1;
            for(int j = ( i << 1); j<=dim; j+=i)
            {
                uz[j] = 1;
            }
        }
    }
}

int main()
{
    ifstream in("ciur.in");

    in >> n;

    ciur();
    sol[0] = 0;
    for(int i = 1; i<=dim; ++i)
    {
        sol[i] = sol[i-1] + sol[i];
    }

    out << sol[n];

    return 0;
}