include builtins/mpfr.e function is_perfect(integer num) mpq tot = mpq_init(), fth = mpq_init() sequence f = factors(num,1) for i=1 to length(f) do mpq_set_si(fth,1,f[i]) mpq_add(tot,tot,fth) end for return mpq_cmp_si(tot,2,1)=0 end function procedure get_perfect_numbers() atom t0 = time() for i=2 to power(2,19) do if is_perfect(i) then printf(1,"perfect: %d\n",i) end if end for printf(1,"elapsed: %3.2f seconds\n",time()-t0) integer pn5 = power(2,12)*(power(2,13)-1) -- 5th perfect number if is_perfect(pn5) then printf(1,"perfect: %d\n",pn5) end if end procedure get_perfect_numbers()