Cod sursa(job #2228962)

Utilizator inquisitorAnders inquisitor Data 5 august 2018 15:27:50
Problema Ciurul lui Eratosthenes Scor 0
Compilator c Status done
Runda Arhiva educationala Marime 0.83 kb
#include <stdio.h>
#include <stdbool.h>
#define MAXN 2000001
#define FIN "ciur.in"
#define FOUT "ciur.out"

//global djs
bool sita[ MAXN ];
int n;

void erathostene();

int main() {

    int i,
        count;

    freopen(FIN, "r", stdin);

    freopen(FOUT, "w", stdout);

    scanf("%d", &n);

    erathostene();

    count = 0;

    for( i = 2; i <= n; ++i )

        if(sita[ i ] == true) count++;

    printf("%d", count);

    return(0);
};

void erathostene() {

     int i,
         j;

     for(i = 2; i <= n; ++i) {

         sita[ i ] = true;
     }

     for(i = 2; i <= n; ++i) {


        if(sita[ i ]) {

                j = 2;

                while( i * j <= n ) {

                       sita[i*j] = false;

                       j++;
                }
        }

     }
}