Erdős-Nicolas numbers: Difference between revisions
→{{header|Perl}}: better performance (~3x faster)
m (→{{header|Wren}}: Changed to Wren S/H) |
(→{{header|Perl}}: better performance (~3x faster)) |
||
Line 1,103:
{{libheader|ntheory}}
<syntaxhighlight lang="perl" line>use v5.36;
use enum qw(False True);
use
return 1 if $n == 0;▼
my @d = divisors($n);▼
sub is_Erdos_Nicolas ($n) {
divisor_sum($n) > 2*$n or return False;
return False unless sum(@divisors) > $n;▼
my $
++$count; $sum += $d;
last if ($sum == $n);
}
return $count;
}
my ($n, $count) = (2, 0);
until ($count == 8) {
next unless 0 == ++$n % 2;
if (my $key = is_Erdos_Nicolas $n) {
printf "%8d == sum of its first %3d divisors\n", $n, $key;
$count++;
}
}</syntaxhighlight>
|