Cod sursa(job #166646)

Utilizator radu_voroneanuVoroneanu Radu Stefan radu_voroneanu Data 28 martie 2008 11:45:24
Problema Ciurul lui Eratosthenes Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.68 kb
var v:array[0..260000] of longint;
    f,g:text;
    i,n,j,nr:longint;

procedure ciur;
 begin
  i:=1;
  while ((i*i) shl 1+(i shl 1))<=n do begin
   if (v[i shr 3] shr (i and 7)) and 1=0 then begin
    j:=((i*i) shl 1+(i shl 1));
    while (j shl 1)+1<=n do begin  {multipli devin false}
     v[j shr 3]:=v[j shr 3] or (1 shl (j and 7));
     j:=j+(i shl 1)+1;
    end;
   end;
   inc(i);
  end;
  nr:=1;
  i:=1;
  while (i shl 1)+1<=n do begin
   if ((v[i shr 3] shr (i and 7)) and 1=0) then
     inc(nr);
   inc(i);
  end;
 end;

begin
 assign(f,'ciur.in'); reset(f);
 assign(g,'ciur.out'); rewrite(g);
 read(f,n);
 ciur;
 writeln(g,nr);
 close(f); close(g);
end.