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


 
EnableExplicit
 
Procedure ListProperDivisors(Number, List Lst())
  If Number < 2 : ProcedureReturn : EndIf
  Protected i
  For i = 1 To Number / 2
    If Number % i = 0
      AddElement(Lst())
      Lst() = i
    EndIf
  Next
EndProcedure
 
Procedure.i CountProperDivisors(Number)
  If Number < 2 : ProcedureReturn 0 : EndIf
  Protected i, count = 0
  For i = 1 To Number / 2
    If Number % i = 0
      count + 1
    EndIf
  Next
  ProcedureReturn count
EndProcedure
 
Define n, count, most = 1, maxCount = 0
If OpenConsole()
  PrintN("The proper divisors of the following numbers are : ")
  PrintN("")
  NewList lst()
  For n = 1 To 10
    ListProperDivisors(n, lst())
    Print(RSet(Str(n), 3) + " -> ")
    If ListSize(lst()) = 0
      Print("(None)")
    Else  
      ForEach lst()
        Print(Str(lst()) + " ")
      Next
    EndIf
    ClearList(lst())
    PrintN("")
  Next
  For n = 2 To 20000
    count = CountProperDivisors(n)
    If count > maxCount
      maxCount = count
      most = n
    EndIf
  Next
  PrintN("")
  PrintN(Str(most) + " has the most proper divisors, namely " + Str(maxCount))
  PrintN("")
  PrintN("Press any key to close the console")
  Repeat: Delay(10) : Until Inkey() <> ""
  CloseConsole()
EndIf
 