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    2n-1,   all known perfect numbers can be derived from these primes
using the formula    (2n - 1) × 2n - 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.


$ include "seed7_05.s7i";
 
const func boolean: isPerfect (in integer: n) is func
  result
    var boolean: isPerfect is FALSE;
  local
    var integer: i is 0;
    var integer: sum is 1;
    var integer: q is 0;
  begin
    for i range 2 to sqrt(n) do
      if n rem i = 0 then
        sum +:= i;
        q := n div i;
        if q > i then
          sum +:= q;
        end if;
      end if;
    end for;
    isPerfect := sum = n;
  end func;
 
const proc: main is func
  local
    var integer: n is 0;
  begin
    for n range 2 to 33550336 do
      if isPerfect(n) then
        writeln(n);
      end if;
    end for;
  end func;