Cod sursa(job #2127595)
Utilizator | Data | 10 februarie 2018 20:22:14 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 30 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <stdio.h>
char v[20000000];
int main() {
int n, i, j, count = 0;
FILE* input = fopen("ciur.in", "r");
FILE* output = fopen("ciur.out", "w");
fscanf(input, "%d", &n);
for (i = 2; i <= n; i++) {
if (v[i] == 0) {
count++;
for (j = i * i; j <= n; j += i) {
v[j] = 1;
}
}
}
fprintf(output, "%d", count);
fclose(input);
fclose(output);
return 0;
}