Код:
var b:array[2..100000] of boolean; i,j,n:longint; begin readln(n); for i:=2 to n do b[i]:= true; i:=2; while i*i<= n do begin if b[i]= true then begin j:=i*i; while j<=n do begin b[j]:=false; j:=j+i; end; end; if i=2 then i:=3 else i:=i+2; end; for i:=2 to n do if b[i] then write(i,' '); end.