NKABD - Số phong phú

Tác giả: khuc_tuan

Ngôn ngữ: Pascal

// {$APPTYPE CONSOLE}
 {$mode delphi}

var
  i, j, sum, dem, a, b : integer;

begin
    read(a,b);
    dem := 0;
    for i:=a to b do
    begin
        sum := 0;
        for j:=1 to i do 
        begin
            if j * j > i then break;
            if sum > i then break;
            if (i mod j)=0 then
            begin
                sum := sum + j;
                if (j<>1) and (j*j<>i) then sum := sum + i div j;
            end;
        end;
        if sum>i then inc(dem);
    end;
    writeln(dem);
    // readln; readln; readln;
end.

Download