Pascal

Modified: Wednesday, 22-12-2021 07:00 AM

var 
tong, n, m,i : longint;
d:byte;
function US (a : longint):longint;
var i : longint;
begin
    tong := 1;
    for i := 2 to trunc(sqrt(a)) do
        if (a mod i=0) then tong := tong+i+(a div i);
        if sqrt(a)=trunc(sqrt(a)) then tong := tong-trunc(sqrt(a));
        us := tong;
end;
begin 
    write('Nhap n : '); readln(n);
    write('Nhap m: '); readln(m);
    d := 0;
    writeln('Cac cap so than thiet tu ',n,' den ',m,' la : ');
    for i:=n to m do 
    begin
        if (us(i)>i)and (us(i)<=m)then
            if(us(us(i)) = i )then 
        begin    
            writeln(i,#32,us(i));
            inc(d);
        end;
    end;
    if (d=0) then write('Khong co');
        readln;
end.