Perfect numbers: Difference between revisions
→Version 2: Now uses Wren-math module.
m (Phix/mpfr) |
(→Version 2: Now uses Wren-math module.) |
||
Line 3,243:
===Version 2===
{{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.
<lang ecmascript>
var isPerfect = Fn.new { |n|
Line 3,276 ⟶ 3,265:
while (count < 7) {
var n = 2.pow(p) - 1
if (
n = n * 2.pow(p-1)
if (isPerfect.call(n)) {
|