Lời giải :
program hotrotinhoc;
var n,i: integer;
function sohoanhao(x: integer): boolean;
var tam,j: integer;
begin
sohoanhao:=false;
for j:=1 to x div 2 do
if x mod j=0 then tam:=tam+j;
if tam=x then sohoanhao:=true;
end;
begin
write('n='); readln(n);
for i:=1 to n do
if sohoanhao(i) then write(i,' ');
readln
end.