program hh_cp;
uses crt;
var n,i:integer;
{---Ham-hoan-hao---}
function hh(k:integer):boolean;
var t,j:integer;
begin
t:=0;
for j:=1 to k div 2 do
if k mod j=0 then t:=t+j;
if t=k then hh:=true esle hh:=false;
end;
{---Ham-chinh-phuong---}
function cp(k:integer):boolean;
begin
if sqr(trunc(sqrt(k)))=k then cp:=true else cp:=false;
end;
{---Chuong-trinh-chinh---}
BEGIN
clrscr;
write('Nhap n: '); readln(n);
for i:=2 to n do
if hh(i) then write(i,' ');
writeln;
for i:=1 to n do
if cp(i) then write(i,' ');
readln;
end.