user
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
assistant
(formerly Perl 6)

```
sub abundant (\x) {
    my @l = x.is-prime ?? 1 !! flat
    1, (2 .. x.sqrt.floor).map: -> \d {
         my \y = x div d;
         next if y * d !== x;
         d !== y ?? (d, y) !! d
    };
    (my $s = @l.sum) > x ?? ($s, |@l.sort(-*)) !! ();
}

my @weird = (2, 4, {|($_ + 4, $_ + 6)} ... *).map: -> $n {
    my ($sum, @div) = $n.&abundant;
    next unless $sum;        # Weird number must be abundant, skip it if it isn't.
    next if $sum / $n > 1.1; # There aren't any weird numbers with a sum:number ratio greater than 1.08 or so.
    if $n >= 10430 and ($n %% 70) and ($n div 70).is-prime {
        # It's weird. All numbers of the form 70 * (a prime 149 or larger) are weird
    } else {
        my $next;
        my $l = @div.shift;
        ++$next and last if $_.sum == $n - $l for @div.combinations;
        next if $next;
    }
    $n
}

put "The first 25 weird numbers:\n", @weird[^25];

```

Output:

```
The first 25 weird numbers:
70 836 4030 5830 7192 7912 9272 10430 10570 10792 10990 11410 11690 12110 12530 12670 13370 13510 13790 13930 14770 15610 15890 16030 16310
```