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


BEGIN # find wierd numbers - abundant but not semiperfect numbers - translation of Go #
    # returns the divisors of n in descending order #
    PROC divisors = ( INT n )[]INT:
         BEGIN
            INT max divs = 2 * ENTIER sqrt( n );
            [ 1 : max divs ]INT divs;
            [ 1 : max divs ]INT divs2;
            INT d pos := 0, d2 pos := 0;
            divs[ d pos +:= 1 ] := 1;
            FOR i FROM 2 WHILE i * i <= n DO
                IF n MOD i = 0 THEN
                    INT j = n OVER i;
                    divs[ d pos +:= 1 ] := i;
                    IF i /= j THEN divs2[ d2 pos +:= 1 ] := j FI
                FI
            OD;
            FOR i FROM d pos BY -1 WHILE i > 0 DO
                divs2[ d2 pos +:= 1 ] := divs[ i ]
            OD;
            divs2[ 1 : d2 pos ]
         END # divisors # ;
    # returns TRUE if n with divisors divs, is abundant, FALSE otherwise #
    PROC abundant = ( INT n, []INT divs )BOOL:
         BEGIN
            INT sum := 0;
            FOR i FROM LWB divs TO UPB divs DO sum +:= divs[ i ] OD;
            sum > n
         END # abundant # ;
    # returns TRUE if n with divisors divs, is semiperfect, FALSE otherwise # 
    PROC semiperfect = ( INT n, []INT divs, INT lb, ub )BOOL:
         IF   ub < lb
         THEN FALSE
         ELIF INT h = divs[ lb ];
              n < h 
         THEN semiperfect( n,     divs, lb + 1, ub )
         ELIF n = h
         THEN TRUE
         ELIF semiperfect( n - h, divs, lb + 1, ub )
         THEN TRUE
         ELSE semiperfect( n,     divs, lb + 1, ub )
         FI # semiperfect # ; 
    # returns a sieve where FALSE = abundant and not semiperfect #
    PROC sieve = ( INT limit )[]BOOL:
         BEGIN # Only interested in even numbers >= 2 #
            [ 1 : limit ]BOOL w; FOR i FROM 1 TO limit DO w[ i ] := FALSE OD;
            FOR i FROM 2 BY 2 TO limit DO
                IF NOT w[ i ] THEN
                    []INT divs = divisors( i );
                    IF NOT abundant( i, divs ) THEN
                        w[ i ] := TRUE
                    ELIF semiperfect( i, divs, LWB divs, UPB divs ) THEN
                        FOR j FROM i BY i TO limit DO w[ j ] := TRUE OD
                    FI
                FI
            OD;
            w
         END # sieve # ;
    BEGIN # task #
        []BOOL w = sieve( 17 000 );
        INT count := 0;
        INT max = 25;
        print( ( "The first 25 weird numbers are:", newline ) );
        FOR n FROM 2 BY 2 WHILE count < max DO
            IF NOT w[ n ] THEN
                print( ( whole( n, 0 ), " " ) );
                count +:= 1
            FI
        OD;
        print( ( newline ) )
    END
END