Cod sursa(job #767284)
| Utilizator | Data | 13 iulie 2012 09:55:54 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int n;
void ciur(){
bool p[n+1];
memset(p,0,sizeof(p));
int i = 2, l = sqrt(n);
while(i <= l)
{
while( p[i] )i++;
for(int j=i*i;j<=n;j+=i) p[j] = 1;
i++;
}
int nr = 0;
for(int i=2;i<=n;i++)
if( !p[i] ) nr++;
printf("%d\n",nr);
}
int main(){
freopen("ciur.in","r",stdin);
freopen("ciur.out","w",stdout);
scanf("%d",&n);
ciur();
return 0;
}
