Cod sursa(job #2641362)
Utilizator | Teofil teofilotopeni | Data | 11 august 2020 11:03:02 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 50 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <stdio.h>
using namespace std;
int v[20000005];
int main()
{
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
int n, tot = 0, i, j;
scanf("%d", &n);
for (i = 3; i < n; i += 2) v[i] = 1;
for (i = 2; i <= n; i++) {
if (v[i] && i % 2) {
tot++;
for (j = 2 * i; j <= n; j += i) v[j] = 0;
}
else if (i == 2) tot++;
}
printf("%d", tot);
return 0;
}