Jump to content

Square-free integers: Difference between revisions

m
(added FreeBASIC)
m (→‎{{header|Perl 6}}: Minor tweaks.)
Line 690:
=={{header|Perl 6}}==
{{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 than this.
 
<lang perl6># Prime factorization routines
Line 701:
 
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 $rho = 1;
Line 718 ⟶ 722:
 
# Task routine
multisub is-square-free (Int $n) { my @v = $n.&prime-factors.Bag.values; not @v.sum/@v ><= 1 }
 
# The Task
10,339

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.