Cod sursa(job #1469287)

Utilizator needforspeedRazor Callahan needforspeed Data 7 august 2015 22:17:17
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <bits/stdc++.h>

#define Nmax 2000005
///#define Pmax 348514
#define Nrp 150005
using namespace std;
int Pmax;

bitset<Nmax> ciur;
int st,vf;

void sieve(){
    ++st;
    vf = 2;
    int d;
    for(auto i = 1; vf <= Pmax; ++i)
        if(!ciur[(i<<1)|1]){
            d = (i<<1|1);
            vf = d; ++st;
            for(int j = 1; d*((j<<1)|1) < Nmax; ++j)
                ciur[d*((j<<1)|1)] = true;
        }
    printf("%d\n",st-1);
}


int main()
{
    freopen("ciur.in","r",stdin);
    freopen("ciur.out","w",stdout);

    scanf("%d",&Pmax);
    sieve();

    return 0;
}