40 lines
884 B
Plaintext
40 lines
884 B
Plaintext
FUNCTION CountProperDivisors (number)
|
|
IF number < 2 THEN CountProperDivisors = 0
|
|
count = 0
|
|
FOR i = 1 TO number \ 2
|
|
IF number MOD i = 0 THEN count = count + 1
|
|
NEXT i
|
|
CountProperDivisors = count
|
|
END FUNCTION
|
|
|
|
SUB ListProperDivisors (limit)
|
|
IF limit < 1 THEN EXIT SUB
|
|
FOR i = 1 TO limit
|
|
PRINT USING "## ->"; i;
|
|
IF i = 1 THEN PRINT " (None)";
|
|
FOR j = 1 TO i \ 2
|
|
IF i MOD j = 0 THEN PRINT " "; j;
|
|
NEXT j
|
|
PRINT
|
|
NEXT i
|
|
END SUB
|
|
|
|
most = 1
|
|
maxCount = 0
|
|
|
|
PRINT "The proper divisors of the following numbers are: "; CHR$(10)
|
|
ListProperDivisors (10)
|
|
|
|
FOR n = 2 TO 20000
|
|
'' It is extremely slow in this loop
|
|
count = CountProperDivisors(n)
|
|
IF count > maxCount THEN
|
|
maxCount = count
|
|
most = n
|
|
END IF
|
|
NEXT n
|
|
|
|
PRINT
|
|
PRINT most; " has the most proper divisors, namely "; maxCount
|
|
END
|