The   proper divisors   of a positive integer N are those numbers, other than N itself, that divide N without remainder.

For N > 1 they will always include 1,   but for N == 1 there are no proper divisors.



Examples

The proper divisors of     6     are   1, 2, and 3.

The proper divisors of   100   are   1, 2, 4, 5, 10, 20, 25, and 50.



Task

 Create a routine to generate all the proper divisors of a number.
 use it to show the proper divisors of the numbers 1 to 10 inclusive.
 Find a number in the range 1 to 20,000 with the most proper divisors. Show the number and just the count of how many proper divisors it has.


Show all output here.



Related tasks

   Amicable pairs
   Abundant, deficient and perfect number classifications
   Aliquot sequence classifications
   Factors of an integer
   Prime decomposition


 
program ProperDivisors;
 
{$APPTYPE CONSOLE}
 
{$R *.res}
 
uses
  System.SysUtils,
  System.Generics.Collections;
 
type
  TProperDivisors = TArray<Integer>;
 
function GetProperDivisors(const value: Integer): TProperDivisors;
var
  i, count: Integer;
begin
  count := 0;
 
  for i := 1 to value div 2 do
  begin
    if value mod i = 0 then
    begin
      inc(count);
      SetLength(result, count);
      Result[count - 1] := i;
    end;
  end;
end;
 
procedure Println(values: TProperDivisors);
var
  i: Integer;
begin
  Write('[');
  if Length(values) > 0 then
    for i := 0 to High(values) do
      Write(Format('%2d', [values[i]]));
  Writeln(']');
end;
 
var
  number, max_count, count, max_number: Integer;
 
begin
  for number := 1 to 10 do
  begin
    write(number, ': ');
    Println(GetProperDivisors(number));
  end;
 
  max_count := 0;
  for number := 1 to 20000 do
  begin
    count := length(GetProperDivisors(number));
    if count > max_count then
    begin
      max_count := count;
      max_number := number;
    end;
  end;
 
  Write(max_number, ': ', max_count);
 
  readln;
end.
 