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


 
FUNCTION ProperDivisor(nr, show)
 
    LOCAL probe, total
 
    FOR probe = 1 TO nr-1
        IF MOD(nr, probe) = 0 THEN
            IF show THEN PRINT " ", probe;
            INCR total
        END IF
    NEXT
 
    RETURN total
 
END FUNCTION
 
FOR x = 1 TO 10
    PRINT x, ":";
    IF ProperDivisor(x, 1) = 0 THEN PRINT " 0";
    PRINT
NEXT
 
FOR x = 1 TO 20000
    DivisorCount = ProperDivisor(x, 0)
    IF DivisorCount > MaxDivisors THEN
        MaxDivisors = DivisorCount
        MagicNumber = x
    END IF
NEXT
 
PRINT "Most proper divisors for number in the range 1-20000: ", MagicNumber, " with ", MaxDivisors, " divisors."
 