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


 
factor=: [: }: [: , [: */&> [: { [: <@(^ i.@>:)/"1 [: |: __&q:
 
classify=: 3 : 0
 weird =: perfect =: deficient =: abundant =: i. 0
 a=: (i. -. 0 , deficient =: 1 , i.&.:(p:inv)) y NB. a are potential semi-perfect numbers
 for_n. a do.
  if. n e. a do.
   factors=. factor n
   sf =. +/ factors
   if. sf < n do.
    deficient =: deficient , n
   else.
    if. n < sf do.
     abundant=: abundant , n
    else.
     perfect =: perfect , n
     a =: a -. (2+i.)@<.&.(%&n) y  NB. remove multiples of perfect numbers
     continue.
    end.
    NB. compute sums of subsets to detect semiperfection
    NB. the following algorithm correctly finds weird numbers less than 20000
    NB. remove large terms necessary for the sum to reduce the Catalan tally of sets
    factors =. /:~ factors  NB. ascending sort
    NB. if the sum of the length one outfixes is less n then the factor is required in the semiperfect set.
    i_required =. n (1 i.~ (>(1+/\.]))) factors
    target =. n - +/ i_required }. factors
    t =. i_required {. factors
    NB. work in chunks of 2^16 to reduce memory requirement
    sp =. target e. ; (,:~2^16) <@([: +/"1 t #~ (_ ,(#t)) {. #:);.3 i. 2 ^ # t
    if. sp do.
     a =: a -. (2+i.)@<.&.(%&n) y  NB. remove multiples of semi perfect numbers
    else.
     weird =: weird , n
     a =: a -. n
    end.
   end.    
  end.
 end.
 a =: a -. deficient
 weird
)
 