Curzon numbers: Difference between revisions
Content added Content deleted
(→{{header|ALGOL 68}}: Tweak) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: more efficient calculations) |
||
Line 1,091: | Line 1,091: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|ntheory}} |
|||
<syntaxhighlight lang="perl">use strict; |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use ntheory 'powmod'; |
|||
sub modpow { |
|||
my($b,$e,$m) = @_; |
|||
my $p = 1; |
|||
while ($e) { |
|||
$p = $p * $b % $m if $e & 1; |
|||
$b = $b * $b % $m; |
|||
$e >>= 1 |
|||
} |
|||
$p |
|||
} |
|||
sub curzon { |
sub curzon { |
||
Line 1,110: | Line 1,101: | ||
while (++$n) { |
while (++$n) { |
||
my $r = $base * $n; |
my $r = $base * $n; |
||
push @C, $n if |
push @C, $n if powmod($base, $n, $base * $n + 1) == $base * $n; |
||
return @C if $cnt == @C; |
return @C if $cnt == @C; |
||
} |
} |