Var n,i,k:integer;
p,pr:set of byte;
function prost(n:integer):boolean;
var j,m:integer;
begin
m:=0;
for j:=2 to trunc(sqrt(n)) do
if n mod j = 0 then inc(m);
prost:=m=0;
end;
begin
readln(n);
writeln('1:');
for i:=2 to n do
if prost(i) then write(i,' ');
writeln;
writeln('2:');
p:=[2..n]; pr:=[];
k:=2;
repeat
while not(k in p) do k:=k+1;
pr:=pr+[k];
i:=k;
repeat
p:=p-[i]; i:=i+k;
until i>n;
until p=[];
for i:=2 to n do
if i in pr then write(i,' ');
writeln;
end.
Пример:
40
1:
2 3 5 7 11 13 17 19 23 29 31 37
2:
2 3 5 7 11 13 17 19 23 29 31 37