Cod sursa(job #1128301)
| Utilizator | Data | 27 februarie 2014 16:27:23 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <cstdio>
#include <cmath>
#define NMAX 2000007
using namespace std;
bool v[NMAX];
int n;
void ciur(int n){
v[0] = v[1] = 1;
for(int i = 4; i <= n; i += 2)
v[i] = 1;
int Lim = sqrt(n);
for(int i = 3; i <= Lim; i += 2)
if(v[i] == 0)
for(int j = i * 2; j <= n; j += i)
v[j] = 1;
}
int main(){
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
scanf("%d", &n);
ciur(n);
int Ans = 0;
for(int i = 1; i <= n; ++i)
Ans += !(v[i]);
printf("%d", Ans);
return 0;
}
