Cod sursa(job #161229)
| Utilizator | Data | 17 martie 2008 19:31:39 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.76 kb |
#include<stdio.h>
#include<math.h>
#define nmax 2000001
int n, t[nmax], ct;
void read()
{
freopen("ciur.in","r",stdin);
freopen("ciur.out","w",stdout);
scanf("%d", &n);
}
void ciur_erathostenes()
{
int i;
int radical= int (sqrt(n));
for(i=2; i<=radical;++i)
if(t[i]==0)
{
int k=i*i;
while(k<=n)
{
t[k]=1;
k=k+i;
}
}
}
void print()
{
int i;
for(i=2;i<=n;++i)
if(t[i]==0)
ct++;
printf("%d\n",ct);
}
int main()
{
read();
ciur_erathostenes();
print();
return 0;
}
