Cod sursa(job #1700393)
| Utilizator | Data | 10 mai 2016 14:10:28 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <bits/stdc++.h>
using namespace std;
int n , i;
vector < int > p , low;
int main()
{
freopen("ciur.in","r",stdin);
freopen("ciur.out","w",stdout);
scanf("%d", &n);
low = vector < int > (n + 1 , 0);
for (i = 2; i <= n; ++i)
{
if (low[i] == 0) low[i] = i, p.push_back(i);
for (auto &it : p)
{
if (it > low[i] || it * i > n) break;
low[it*i] = it;
}
}
printf("%d\n", (int)p.size());
return 0;
}
