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


 
' FreeBASIC v1.05.0 win64
 
Sub ListProperDivisors(limit As Integer)
  If limit < 1 Then Return
  For i As Integer = 1 To limit
     Print Using "##"; i; 
     Print " ->";
     If i = 1 Then 
       Print " (None)"
       Continue For
     End if
     For j As Integer = 1 To i \ 2
       If i Mod j = 0 Then Print " "; j;
     Next j
     Print
  Next i
End Sub
 
Function CountProperDivisors(number As Integer) As Integer
  If number < 2 Then Return 0
  Dim count As Integer = 0
  For i As Integer = 1 To number \ 2
    If number Mod i = 0 Then count += 1
  Next
  Return count
End Function
 
Dim As Integer n, count, most = 1, maxCount = 0
 
Print "The proper divisors of the following numbers are :"
Print
ListProperDivisors(10)
 
For n As Integer = 2 To 20000
  count = CountProperDivisors(n)
  If count > maxCount Then
    maxCount = count
    most = n
  EndIf
Next
 
Print
Print Str(most); " has the most proper divisors, namely"; maxCount
Print
Print "Press any key to exit the program"
Sleep
End
 