Cod sursa(job #900697)
Utilizator | Data | 28 februarie 2013 21:20:40 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include<cstdio>
#define nmax 2000005
using namespace std;
int n,count;
char used[nmax];
int main()
{
int i,j;
freopen("ciur.in","r",stdin);
freopen("ciur.out","w",stdout);
scanf("%d", &n);
for(i=2; i<=n; ++i)
used[i]=1;
for(i=2; i<=n; ++i)
if(used[i])
{
++count;
for(j=i+i; j<=n; j+=i)
used[j]=0;
}
printf("%d\n", count);
return 0;
}