Cod sursa(job #1926056)

Utilizator GandalfTheWhiteGandalf the White GandalfTheWhite Data 13 martie 2017 22:21:25
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <cstdio>
using namespace std;

int n,nr;
bool P[2000003];

void Sieve(){

    int i,j;

    for (i=4;i<=n;i+=2) P[i]=1;

    for (i=3;i*i<=n;i+=2)
        for (j=i*i;j<=n;j+=i)
            P[j]=1;
}

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

    scanf("%d",&n);

    Sieve();

    for (int i=4;i<=n;i++)
        nr+=P[i];
    printf("%d",n-nr-1);
    return 0;
}