Square-free integers: Difference between revisions
Content deleted Content added
added FreeBASIC |
Thundergnat (talk | contribs) m →{{header|Perl 6}}: Minor tweaks. |
||
Line 690: | Line 690: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{works with|Rakudo|2018.06}} |
{{works with|Rakudo|2018.06}} |
||
The prime factoring algorithm is not really the best option for finding long runs of sequential square-free numbers. It works, but is probably better suited for testing arbitrary numbers rather than testing every sequential number from 1 to some limit. If you know that that is going to be your use case, there are faster algorithms |
The prime factoring algorithm is not really the best option for finding long runs of sequential square-free numbers. It works, but is probably better suited for testing arbitrary numbers rather than testing every sequential number from 1 to some limit. If you know that that is going to be your use case, there are faster algorithms. |
||
<lang perl6># Prime factorization routines |
<lang perl6># Prime factorization routines |
||
Line 701: | Line 701: | ||
sub find-factor ( Int $n, $constant = 1 ) { |
sub find-factor ( Int $n, $constant = 1 ) { |
||
return 2 unless $n +& 1; |
|||
if (my $gcd = $n gcd 6541380665835015) > 1 { |
|||
return $gcd if $gcd != $n |
|||
} |
|||
my $x = 2; |
my $x = 2; |
||
my $rho = 1; |
my $rho = 1; |
||
Line 718: | Line 722: | ||
# Task routine |
# Task routine |
||
sub is-square-free (Int $n) { my @v = $n.&prime-factors.Bag.values; @v.sum/@v <= 1 } |
|||
# The Task |
# The Task |