Cod sursa(job #1164765)
Utilizator | Data | 2 aprilie 2014 12:06:57 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include<stdio.h>
#define nmax 2000005
int d, n, j, rez, i;
bool npr[nmax];
void ciur()
{
for(d=2;d*d<=n;d++)
if (!npr[d])
for (j=2;j*d<=n;j++)
npr[j*d]=1;
}
int main()
{
freopen("ciur.in","r",stdin);
freopen("ciur.out","w",stdout);
scanf("%ld",&n);
ciur();
for (i=2;i<=n;i++)
rez+=(1-npr[i]);
printf("%ld",rez);
return 0;
}