Chernick's Carmichael numbers: Difference between revisions

Content added Content deleted
(Chernick's Carmichael numbers in FreeBASIC)
m (→‎{{header|Raku}}: note use of 'ntheory' module)
Line 1,354: Line 1,354:
=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(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 for primality testing since it is much, ''much'' faster than Raku's built-in .is-prime method.
{{trans|Perl}}
{{libheader|ntheory}}
<lang perl6>use Inline::Perl5;
<lang perl6>use Inline::Perl5;
use ntheory:from<Perl5> <:all>;
use ntheory:from<Perl5> <:all>;


sub chernick-factors ($n, $m) {
sub chernick-factors ($n, $m) {
6*$m + 1, 12*$m + 1, |((1 .. $n-2).map: { (1 +< $_) * 9*$m + 1 } )
$m + 1, 12×$m + 1, |((1 .. $n-2).map: { (1 +< $_) × $m + 1 } )
}
}


Line 1,368: Line 1,368:


my $multiplier = 1 +< (($n-4) max 0);
my $multiplier = 1 +< (($n-4) max 0);
my $iterator = $n < 5 ?? (1 .. *) !! (1 .. *).map: * * 5;
my $iterator = $n < 5 ?? (1 .. *) !! (1 .. *).map: * × 5;


$multiplier * $iterator.first: -> $m {
$multiplier × $iterator.first: -> $m {
[&&] chernick-factors($n, $m * $multiplier).map: { is_prime($_) }
[&&] chernick-factors($n, $m × $multiplier).map: { is_prime($_) }
}
}


Line 1,379: Line 1,379:
my $m = chernick-carmichael-number($n);
my $m = chernick-carmichael-number($n);
my @f = chernick-factors($n, $m);
my @f = chernick-factors($n, $m);
say "U($n, $m): {[*] @f} = {@f.join(' ⨉ ')}";
say "U($n, $m): {[×] @f} = {@f.join(' ⨉ ')}";
}</lang>
}</lang>
{{out}}
{{out}}