Abundant, deficient and perfect number classifications
These define three classifications of positive integers based on their proper divisors.
Let P(n) be the sum of the proper divisors of n, where the proper divisors of n are all perfect divisors of n less than n.
- if P(n) < n then n is classed as deficient.
- if P(n) == n then n is classed as perfect.
- if P(n) > n then n is classed as abundant.
Example: 6 has proper divisors 1, 2, and 3. 1 + 2 + 3 = 6 so 6 is classed as a perfect number.
- Task
Calculate how many of the integers 1 to 20,000 inclusive are in each of the three classes and show the result here.
- Cf.
Python
Importing Proper divisors from prime factors: <lang python>>>> from proper_divisors import proper_divs >>> from collections import Counter >>> >>> rangemax = 20000 >>> >>> def pdsum(n): ... return sum(proper_divs(n)) ... >>> def classify(n, p): ... return 'perfect' if n == p else 'abundant' if p > n else 'deficient' ... >>> classes = Counter(classify(n, pdsum(n)) for n in range(1, 1 + rangemax)) >>> classes.most_common() [('deficient', 15042), ('abundant', 4953), ('perfect', 5)] >>> </lang>