Chernick's Carmichael numbers: Difference between revisions

m
→‎{{header|Raku}}: note use of 'ntheory' module
(Chernick's Carmichael numbers in FreeBASIC)
m (→‎{{header|Raku}}: note use of 'ntheory' module)
Line 1,354:
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2019.03}}
{{trans|Perl}}
Use the ntheory library from Perl 5 for primality testing since it is much, ''much'' faster than Rakus built-in .is-prime method.
 
Use the ntheory library from Perl 5 for primality testing since it is much, ''much'' faster than RakusRaku's built-in .is-prime method.
{{trans|Perl}}
{{libheader|ntheory}}
<lang perl6>use Inline::Perl5;
use ntheory:from<Perl5> <:all>;
 
sub chernick-factors ($n, $m) {
6*$m + 1, 12*12×$m + 1, |((1 .. $n-2).map: { (1 +< $_) *× 9*$m + 1 } )
}
 
Line 1,368:
 
my $multiplier = 1 +< (($n-4) max 0);
my $iterator = $n < 5 ?? (1 .. *) !! (1 .. *).map: * *× 5;
 
$multiplier *× $iterator.first: -> $m {
[&&] chernick-factors($n, $m *× $multiplier).map: { is_prime($_) }
}
 
Line 1,379:
my $m = chernick-carmichael-number($n);
my @f = chernick-factors($n, $m);
say "U($n, $m): {[*×] @f} = {@f.join(' ⨉ ')}";
}</lang>
{{out}}
2,392

edits