Cod sursa(job #164086)

Utilizator iiipppPUSCASU ION iiippp Data 23 martie 2008 15:20:09
Problema Ciurul lui Eratosthenes Scor 30
Compilator fpc Status done
Runda Arhiva educationala Marime 0.43 kb
var ok:array[2..30000] of boolean;
i,j,n,k:LONGINT; f,g:text;
begin
assign(f, 'ciur.in');
reset(f);
readln(f,n);
assign(g,'ciur.out');
rewrite(g);
for i:=2 to n do
ok[i]:=true;
for i:=2 to trunc(sqrt(n)) do
if ok[i] then
   begin
     j:=2;
     while i*j<=n do begin
     ok[i*j]:=false;
     inc(j);
     end;
 end;
     for i:=2 to n do
     if ok[i] then k:=k+1;
     write(g,k);
 close(f);
 close(g);
     end.