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 are all positive divisors of   n   other than   n   itself.

   if    P(n) <  n    then  n  is classed as  deficient  (OEIS A005100).
   if    P(n) == n    then  n  is classed as  perfect    (OEIS A000396).
   if    P(n) >  n    then  n  is classed as  abundant   (OEIS A005101).



Example

6   has proper divisors of   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.

Show the results here.



Related tasks

   Aliquot sequence classifications.   (The whole series from which this task is a subset.)
   Proper divisors
   Amicable pairs


 
print "ROSETTA CODE - Abundant, deficient and perfect number classifications"
print
for x=1 to 20000
    x$=NumberClassification$(x)
    select case x$
        case "deficient": de=de+1
        case "perfect": pe=pe+1: print x; " is a perfect number"
        case "abundant": ab=ab+1
    end select
    select case x
        case 2000: print "Checking the number classifications of 20,000 integers..."
        case 4000: print "Please be patient."
        case 7000: print "7,000"
        case 10000: print "10,000"
        case 12000: print "12,000"
        case 14000: print "14,000"
        case 16000: print "16,000"
        case 18000: print "18,000"
        case 19000: print "Almost done..."
    end select
next x
print "Deficient numbers = "; de
print "Perfect numbers = "; pe
print "Abundant numbers = "; ab
print "TOTAL = "; pe+de+ab
[Quit]
print "Program complete."
end
 
function NumberClassification$(n)
    x=ProperDivisorCount(n)
    for y=1 to x
        PDtotal=PDtotal+ProperDivisor(y)
    next y
    if PDtotal=n then NumberClassification$="perfect": exit function
    if PDtotal<n then NumberClassification$="deficient": exit function
    if PDtotal>n then NumberClassification$="abundant": exit function
end function
 
function ProperDivisorCount(n)
    n=abs(int(n)): if n=0 or n>20000 then exit function
    dim ProperDivisor(100)
    for y=2 to n
        if (n mod y)=0 then
            ProperDivisorCount=ProperDivisorCount+1
            ProperDivisor(ProperDivisorCount)=n/y
        end if
    next y
end function
 