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


func sieve(bound) {
    var (a, d, p) = (0, 0, 0)
    var sum = Array.Empty(bound + 1, 0)
 
    for divisor in 1..(bound / 2) {
        var i = divisor + divisor
        while i <= bound {
            sum[i] += divisor
            i += divisor
        }
    }
    for i in 1..bound {
        if sum[i] < i {
            d += 1
        } else if sum[i] > i {
            a += 1
        } else {
            p += 1
        }
    }
 
    (abundant: a, deficient: d, perfect: p)
}
 
func Iterator.Where(fn) {
    for x in this {
        if fn(x) {
            yield x
        }
    }
}
 
func Iterator.Sum() {
    var sum = 0
    for x in this {
        sum += x
    }
    sum
}
 
func division(bound) {
    var (a, d, p) = (0, 0, 0)
    for i in 1..20000 {
        var sum = ( 1 .. ((i + 1) / 2) )
            .Where(div => div != i && i % div == 0)
            .Sum()
        if sum < i {
            d += 1
        } else if sum > i {
            a += 1
        } else {
            p += 1
        }
    }
 
    (abundant: a, deficient: d, perfect: p)
}
 
func out(res) {
    print("Abundant: \(res.abundant), Deficient: \(res.deficient), Perfect: \(res.perfect)");
}
 
out( sieve(20000) )
out( division(20000) )