Cod sursa(job #1700429)
| Utilizator | Data | 10 mai 2016 15:09:27 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 2e6 + 10;
int n , i , ans;
unsigned char low[nmax];
int p[1510];
int main()
{
freopen("ciur.in","r",stdin);
freopen("ciur.out","w",stdout);
scanf("%d", &n);
for (i = 2; i <= n; ++i)
{
if (low[i] == 0)
{
ans++;
if (i <= 1500) p[++p[0]] = i;
}
for (int j = 1; j <= p[0]; ++j)
{
int it = p[j];
if ((it > p[low[i]] && low[i] != 0) || it * i > n) break;
low[it*i] = j;
}
}
printf("%d\n", ans);
return 0;
}
