Cod sursa(job #599327)

Utilizator Luncasu_VictorVictor Luncasu Luncasu_Victor Data 28 iunie 2011 15:20:12
Problema Ciurul lui Eratosthenes Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.93 kb
const   fin = 'ciur.in'; fout = 'ciur.out'; max = 1000 * 2000;

type
        tabelprime = array[1..max] of boolean;
var
        prim : tabelprime;

procedure prime();
var
        j ,i ,x : longword;
begin
        x := trunc(sqrt(max));
        i := 1;
        prim[1] := true;
        while (i <= x) do
        begin
                repeat i := i + 1; until not prim[i];
                j := i * i;
                while (j <= max) do
                begin
                        prim[j] := true;
                        j := j + i;
                end;
        end;
end;

procedure main();
var
        n ,i ,x : longword;
begin
        assign( input, fin ); reset( input );
        assign( output, fout ); rewrite ( output );

        prime();

        readln( n );

        x := 0;
        for i := 1 to n do
        if not prim[i] then x := x + 1;

        write(x, #10);
end;

begin
        main();
end.