Var a, b, i, j: longint; ar: array of boolean; begin readln(a, b); setlength(ar, b); for i := 1 to b do ar[i - 1] := true; i := 2; while (sqr(i) <= b) do begin if(ar[i - 1] = true) then begin j := sqr(i); while (j <= b) do begin ar[j - 1] := false; j := j + i; end; end; i := i + 1; end; for i := a to b do if(ar[i - 1] = true) then write(i, ' '); end.
Answers & Comments
Verified answer
Vara, b, i, j: longint;
ar: array of boolean;
begin
readln(a, b);
setlength(ar, b);
for i := 1 to b do ar[i - 1] := true;
i := 2;
while (sqr(i) <= b) do
begin
if(ar[i - 1] = true) then
begin
j := sqr(i);
while (j <= b) do
begin
ar[j - 1] := false;
j := j + i;
end;
end;
i := i + 1;
end;
for i := a to b do
if(ar[i - 1] = true) then write(i, ' ');
end.