Cod sursa(job #289639)

Utilizator danalex97Dan H Alexandru danalex97 Data 26 martie 2009 21:17:29
Problema Ciurul lui Eratosthenes Scor 30
Compilator fpc Status done
Runda Arhiva educationala Marime 0.6 kb
var f,g:text;
    n,c,j,i:longint;
    ok:boolean;
begin
assign(f,'ciur.in');
reset(f);
assign(g,'ciur.out');
rewrite(g);
read(f,n);
if n=2 then write(g,'1')
else if n=3 then write(g,'2')
else if n>3 then
  begin
    i:=3;
    c:=2;
    while i+2<=n do
      begin
        inc(i,2);
        ok:=true;
        j:=3;
        if i div 2=0 then ok:=false;
        while (j<=trunc(sqrt(i)))and(ok) do
          begin
             if i mod j=0 then ok:=false;
            inc(j,2);
          end;
        if ok then inc(c);
      end;
    write(g,c);
  end;
close(f);
close(g);
end.