Cod sursa(job #2604343)

Utilizator lepoartcevPaltineanu Rares-Mihai lepoartcev Data 22 aprilie 2020 14:56:34
Problema Ciurul lui Eratosthenes Scor 50
Compilator c-64 Status done
Runda Arhiva educationala Marime 0.55 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) * 2000001);

    for(int i = 0; i <= n; i++)
        array[i] = 0;

    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;
}