Cod sursa(job #1669782)
Utilizator | Chilivercu Cristian Anonymous1010 | Data | 31 martie 2016 00:55:41 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <stdio.h>
#define N 2000001
char not_prime[N];
int n, total;
void sift(int prime)
{
int i;
for (i = 3; i <= n / prime; i += 2)
not_prime[i * prime] = 1;
}
int main()
{
int i, nsqrt;
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
scanf("%d", &n);
total++;
for (i = 3; i < n; i += 2)
if (!not_prime[i]) {
sift(i);
total++;
}
printf("%d\n", total);
}