Cod sursa(job #1469285)

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

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

array<bool,Nmax> ciur;
array<int,Nrp>prime;
int st;

void sieve(){
    prime[++st] = 2;
    int d;
    for(auto i = 1; prime[st] <= Pmax; ++i)
        if(!ciur[(i<<1)|1]){
            d = (i<<1|1);
            prime[++st] = d;
            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;
}