user
Write a function which says whether a number is perfect.

A perfect number is a positive integer that is the sum of its proper positive divisors excluding the number itself.

Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including itself).

Note:   The faster   Lucas-Lehmer test   is used to find primes of the form    2*n*-1,   all *known* perfect numbers can be derived from these primes
using the formula    (2*n* - 1) × 2*n* - 1.

It is not known if there are any odd perfect numbers (any that exist are larger than 102000).

The number of   *known*   perfect numbers is   **51**   (as of December, 2018),   and the largest known perfect number contains  **49,724,095**  decimal digits.

See also
:   * Rational Arithmetic
    * Perfect numbers on OEIS
    * Odd Perfect showing the current status of bounds on odd perfect numbers.
assistant
(formerly Perl 6)
Naive (very slow) version

```
sub is-perf($n) { $n == [+] grep $n %% *, 1 .. $n div 2 }

# used as
put ((1..Inf).hyper.grep: {.&is-perf})[^4];
```

Output:

```
6 28 496 8128
```

Much, much faster version:

```
my @primes   = lazy (2,3,*+2 … Inf).grep: { .is-prime };
my @perfects = lazy gather for @primes {
    my $n = 2**$_ - 1;
    take $n * 2**($_ - 1) if $n.is-prime;
}

.put for @perfects[^12];
```

Output:

```
6
28
496
8128
33550336
8589869056
137438691328
2305843008139952128
2658455991569831744654692615953842176
191561942608236107294793378084303638130997321548169216
13164036458569648337239753460458722910223472318386943117783728128
14474011154664524427946373126085988481573677491474835889066354349131199152128
```