Cod sursa(job #156969)

Utilizator ghitza_2000Stefan Gheorghe ghitza_2000 Data 12 martie 2008 20:16:32
Problema Ciurul lui Eratosthenes Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.5 kb
var f,g:text;
a:array[1..2000000] of byte;
procedure erathostenes;
var n,ct,i,j:longint;
begin
readln(f,n);
ct:=0;
for i:=2 to n do
if a[i]=0 then begin
                  inc(ct);
                  j:=i+i;
                  while j<=n do
                  begin
                  a[j]:=1;
                  j:=j+i;
                  end;
               end;
writeln(g,ct);
end;
begin
assign(f,'ciur.in'); reset(f);
assign(g,'ciur.out'); rewrite(g);
erathostenes;
close(f); close(g);
end.