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


$ include "seed7_05.s7i";
 
const proc: writeProperDivisors (in integer: n) is func
  local
    var integer: i is 0;
  begin
    for i range 1 to n div 2 do
      if n rem i = 0 then
        write(i <& " ");
      end if;
    end for;
    writeln;
  end func;
 
const func integer: countProperDivisors (in integer: n) is func
  result
    var integer: count is 0;
  local
    var integer: i is 0;
  begin
    for i range 1 to n div 2 step succ(n rem 2) do
      if n rem i = 0 then
        incr(count);
      end if;
    end for;
  end func;
 
const proc: main is func
  local
    var integer: i is 0;
    var integer: v is 0;
    var integer: max is 0;
    var integer: max_i is 1;
  begin
    for i range 1 to 10 do
      write(i <& ": ");
      writeProperDivisors(i);
    end for;
    for i range 1 to 20000 do
      v := countProperDivisors(i);
      if v > max then
        max := v;
        max_i := i;
      end if;
    end for;
    writeln(max_i <& " with " <& max <& " divisors");
  end func;