Cod sursa(job #1908631)
Utilizator | Data | 7 martie 2017 09:44:03 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include <cstdio>
#include <vector>
using namespace std;
vector<bool> b(2000005, false);
int main()
{
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
int n;
scanf("%d", &n);
fclose(stdin);
for(int i = 4; i <= n; i += 2) b[i] = 1;
for(int i = 3; i * i <= n; i += 2)
if(!b[i])
for(int j = i * i; j <= n; j += 2 * i) b[j] = 1;
int ct = 0;
for(int i = 2; i <= n; ++i)
if(!b[i]) ct++;
printf("%d", ct);
fclose(stdout);
return 0;
}