Cod sursa(job #731553)

Utilizator test0Victor test0 Data 8 aprilie 2012 13:54:14
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.38 kb
#include <stdio.h>
bool p[2000001];
int n,nr;

void ciur(){
    int i=2,j;
    while(i<=1412){
        while(p[i])i++;
        for(j=i*i;j<=2000000;j+=i)p[j]=1;
        i++; }
}

int main(){
    int i;
    freopen("ciur.in","r",stdin);
    freopen("ciur.out","w",stdout);
        scanf("%d",&n);
        ciur();
        for(int i=2;i<=n;i++)if(!p[i])nr++;
        printf("%d\n",nr);
}