In number theory, a weird number is a natural number that is abundant but not semiperfect (and therefore not perfect either).

In other words, the sum of the proper divisors of the number (divisors including 1 but not itself) is greater than the number itself (the number is abundant), but no subset of those divisors sums to the number itself (the number is not semiperfect).

For example:

 12 is not a weird number.
 It is abundant; its proper divisors 1, 2, 3, 4, 6 sum to 16 (which is > 12),
 but it is semiperfect, e.g.:     6 + 4 + 2 == 12.
 70 is a weird number.
 It is abundant; its proper divisors 1, 2, 5, 7, 10, 14, 35 sum to 74 (which is > 70),
 and there is no subset of proper divisors that sum to 70.


Task

Find and display, here on this page, the first 25 weird numbers.



Related tasks

 Abundant, deficient and perfect number classifications
 Proper divisors


See also

 OEIS: A006037 weird numbers
 Wikipedia: weird number
 MathWorld: weird number


with javascript_semantics
function abundant(integer n, sequence divs)
    return sum(divs) > n
end function
 
function semiperfect(integer n, sequence divs)
    if length(divs)=0 then return false end if
    integer h = divs[1]; divs = divs[2..$]
    return n=h
       or (n>h and semiperfect(n-h, divs))
       or          semiperfect(n, divs)
end function
 
function sieve(integer limit)
-- true denotes abundant and not semi-perfect.
-- only interested in even numbers >= 2
    sequence wierd := repeat(true,limit)
    for j=6 to limit by 6 do
        -- eliminate multiples of 3
        wierd[j] = false
    end for
    for i=2 to limit by 2 do
        if wierd[i] then
            sequence divs := factors(i,-1)
            if not abundant(i,divs) then
                wierd[i] = false
            elsif semiperfect(i,divs) then
                for j=i to limit by i do wierd[j] = false end for
            end if
        end if
    end for
    return wierd
end function
 
--constant MAX = 25, sieve_limit = 16313 
constant MAX = 50, sieve_limit = 26533 
 
sequence wierd := sieve(sieve_limit), res = {}
for i=2 to sieve_limit by 2 do
    if wierd[i] then
        res &= i
        if length(res)=MAX then exit end if
    end if
end for
printf(1,"%s\n",{join(shorten(res,"weird numbers",5,"%d"))})
