RosettaCodeData/Task/Proper-divisors/BaCon/proper-divisors.bacon
2023-07-01 13:44:08 -04:00

30 lines
626 B
Text

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."