var P:array[2..100000] of boolean; i, n, pr:integer; flag:boolean; begin write('max = '); readln(n); for i := 2 to n do P[i] := true; pr := 2; flag := true; while flag do begin i := 2 * pr; while i <= n do begin P[i] := false; i := i + pr; end; flag := false; for i := pr + 1 to n do if P[i] then begin pr := i; flag := true; break; end; end;
for i := 10 to n do if P[i] then writeln(i); readln; end.
Answers & Comments
Verified answer
var
P:array[2..100000] of boolean;
i, n, pr:integer;
flag:boolean;
begin
write('max = ');
readln(n);
for i := 2 to n do
P[i] := true;
pr := 2;
flag := true;
while flag do
begin
i := 2 * pr;
while i <= n do
begin
P[i] := false;
i := i + pr;
end;
flag := false;
for i := pr + 1 to n do
if P[i] then
begin
pr := i;
flag := true;
break;
end;
end;
for i := 10 to n do
if P[i] then
writeln(i);
readln;
end.