Cod sursa(job #2604342)
| Utilizator | Data | 22 aprilie 2020 14:53:49 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 50 |
| Compilator | c-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
FILE* in = fopen("ciur.in", "r");
FILE* out = fopen("ciur.out", "w");
int n;
fscanf(in, "%d", &n);
int* array = (int*)malloc(sizeof(int) * (n + 1));
memset(array, 0, sizeof(int) * (n + 1));
int ct = 0;
for(int i = 2; i <= n; i++)
{
if(!array[i]) {
ct++;
for(int j = i * 2; j <= n; j += i)
array[j] = 1;
}
}
fprintf(out, "%d", ct);
return 0;
}
