Cod sursa(job #188937)

Utilizator punkistBarbulescu Dan punkist Data 10 mai 2008 22:10:54
Problema Ciurul lui Eratosthenes Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.43 kb
var f,f2:text;
    ciur:array[1..2000000] of boolean;
    j,i,n,rez,b:longint;

begin
assign(f,'ciur.in');
assign(f2,'ciur.out');
reset(f);
readln(f,n);
close(f);
rez:=0;
for i:=2 to n do
 begin
  if not ciur[i] then
   begin
    rez:=rez+1;
    j:=2;
    b:=i*j;
    while b<=n do
     begin
      ciur[b]:=true;
      j:=j+1;
      b:=i*j;
     end;
   end;
 end;
rewrite(f2);
writeln(f2,rez);
close(f2);
end.