Anonymous user
Perfect numbers: Difference between revisions
m
→{{header|Elena}}
m (→cheating: another three) |
imported>Arakov |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1,625:
=={{header|Elena}}==
ELENA
<syntaxhighlight lang="elena">import system'routines;
import system'math;
Line 1,633:
{
isPerfect()
= new Range(1, self - 1).selectBy::(n => (self.mod
}
public program()
{
for(int n := 1
{
if(n.isPerfect())
Line 3,130:
<syntaxhighlight lang="phix">
include mpfr.e
atom t0 = time()
mpz n = mpz_init(), m = mpz_init()
sequence validp = {2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607,
Line 4,660:
{{trans|D}}
Restricted to the first four perfect numbers as the fifth one is very slow to emerge.
<syntaxhighlight lang="
if (n <= 2) return false
var tot = 1
Line 4,693:
{{libheader|Wren-math}}
This makes use of the fact that all known perfect numbers are of the form <big> (2<sup>''n''</sup> - 1) × 2<sup>''n'' - 1</sup></big> where <big> (2<sup>''n''</sup> - 1)</big> is prime and finds the first seven perfect numbers instantly. The numbers are too big after that to be represented accurately by Wren.
<syntaxhighlight lang="
var isPerfect = Fn.new { |n|
|