Abundant, deficient and perfect number classifications

Revision as of 19:10, 16 December 2014 by rosettacode>Paddy3118 (New draft task and Python solution.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

These define three classifications of positive integers based on their proper divisors.

Abundant, deficient and perfect number classifications is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

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.

{header|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>