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


 
$lines
 
$constant false = 0
$constant true = FFFFH
 
rem - compute p mod q
function mod(p, q = integer) = integer
end = p - q * (p/q)
 
rem - count, and optionally display, proper divisors of n
function divisors(n, display = integer) = integer
  var i, limit, count, start, delta = integer
  if mod(n, 2) = 0 then
    begin
      start = 2
      delta = 1
    end
  else
    begin
      start = 3
      delta = 2
    end
  if n < 2 then count = 0 else count = 1
  if display and (count = 1) then print using "#####"; 1;
  i = start
  limit = n / start
  while i <= limit do
    begin
      if mod(n, i) = 0 then
        begin
          if display then print using "#####"; i;
          count = count + 1
        end
      i = i + delta
      if count = 1 then limit = n / i
    end
  if display then print
end = count
 
rem - main program begins here
var i, ndiv, highdiv, highnum = integer
 
print "Proper divisors of first 10 numbers:" 
for i = 1 to 10 
  print using "### : "; i;
  ndiv = divisors(i, true)
next i
 
print "Searching for number with most divisors ..."
highdiv = 1
highnum = 1
for i = 1 to 20000 
  ndiv = divisors(i, false)
  if ndiv > highdiv then
    begin
      highdiv = ndiv
      highnum = i
    end
next i
print "Searched up to"; i
print highnum; " has the most divisors: "; highdiv
 
end
 