Cod sursa(job #1700430)
| Utilizator | Data | 10 mai 2016 15:13:30 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.64 kb |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 2e6 + 10;
const int Sqrt = 1500;
int n , i , j , ans;
unsigned char low[nmax];
int p[Sqrt+10];
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 <= Sqrt) p[++p[0]] = i;
}
for (j = 1; j <= p[0] && p[j] * i <= n; ++j)
{
if (p[j] > p[low[i]] && low[i] != 0) break;
low[p[j]*i] = j;
}
}
printf("%d\n", ans);
return 0;
}
