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