Cod sursa(job #2031835)
Utilizator | Data | 3 octombrie 2017 21:29:25 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <bits/stdc++.h>
using namespace std;
int n;
bool p[2000005];
int main()
{
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
scanf("%d", &n);
int NR = 1;
for(int i = 3; i * i <= n ; i += 2){
if(p[i] == 0){
for(int j = i * i ; j <= n ; j += (i << 1))
p[j] = 1;
}
}
for(int i = 3; i <= n ; i += 2)
if(p[i] == 0) ++NR;
printf("%d", NR);
return 0;
}