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;
 
Uses fgl;
 
Type 
  TIntegerList = Specialize TfpgList<longint>;
 
Var list : TintegerList;
 
Function GetProperDivisors(x : longint): longint;
{this function will return the number of proper divisors
 and put them in the list}
 
Var i : longint;
Begin
  list.clear;
  If x = 1 Then {by default 1 has no proper divisors}
    GetProperDivisors := 0
  Else
    Begin
      list.add(1); //add 1 as a proper divisor;
      i := 2;
      While i * i < x Do
        Begin
          If (x Mod i) = 0 Then //found a proper divisor
            Begin
              list.add(i); // add divisor
              list.add(x Div i); // add result
            End;
          inc(i);
        End;
      If i*i=x Then list.add(i); //make sure to capture the sqrt only once
      GetProperDivisors := list.count;
    End;
End;
 
Var i,j,count,most : longint;
Begin
 
  list := TIntegerList.Create;
  For i := 1 To 10 Do
    Begin
      write(i:4,' has ', GetProperDivisors(i),' proper divisors:');
      For j := 0 To pred(list.count) Do
        write(list[j]:3);
      writeln();
    End;
  count := 0; //store highest number of proper divisors
  most := 0;  //store number with highest number of proper divisors
  For i := 1 To 20000 Do
    If GetProperDivisors(i) > count Then
      Begin
        count := list.count;
        most := i;
      End;
  writeln(most,' has ',count,' proper divisors');
  list.free;
End.
 