Cod sursa(job #291566)

Utilizator hominiduBirsan Dragos hominidu Data 29 martie 2009 23:49:07
Problema Ciurul lui Eratosthenes Scor 0
Compilator fpc Status done
Runda The Beginners Marime 0.57 kb
var f,g:Text;
    ct,j,n:longint;
function prim(x:integer):boolean;
var i:integer;
	ok:boolean;
begin
ok:=true;
if x=1 then ok:=false;prim:=ok;
if x=2 then ok:=true;prim:=ok;
if x=3 then ok:=true;prim:=ok;
if x mod 2=0 then ok:=false;
i:=3;
if x mod 2<>0 then
while (i<=trunc(sqrt(x))) and (ok) do
begin
i:=i+2;
if x mod i=0 then
ok:=false;
end;
prim:=ok;
end;




BEGIN
assign(f,'ciur.in');
reset(f);
readln(f,n);
close(f);
cT:=0;
for j:=2 to n do
if prim(j) = true then
ct:=ct+1;
assign(g,'ciur.out');
rewrite(g);
writeln(g,ct);
close(g);
END.