Perfect numbers: Difference between revisions

m
m (→‎cheating: another three)
imported>Arakov
 
(2 intermediate revisions by 2 users not shown)
Line 1,625:
 
=={{header|Elena}}==
ELENA 46.x:
<syntaxhighlight lang="elena">import system'routines;
import system'math;
Line 1,633:
{
isPerfect()
= new Range(1, self - 1).selectBy::(n => (self.mod:(n) == 0).iif(n,0) ).summarize(new Integer()) == self;
}
public program()
{
for(int n := 1,; n < 10000,; n += 1)
{
if(n.isPerfect())
Line 3,130:
<syntaxhighlight lang="phix">
include mpfr.e
atom t0 = time(), t1 = t0+1
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="ecmascriptwren">var isPerfect = Fn.new { |n|
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="ecmascriptwren">import "./math" for Int
 
var isPerfect = Fn.new { |n|
Anonymous user