Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 35 lines (26 sloc) 608 Bytes
#!/usr/bin/env perl6
sub prime-factorizatiion(Int $n is copy) {
my @factors;
for (2..*).grep(*.is-prime) -> $p {
my $k = 1;
while $n % $p == 0 {
$n = $n div $p;
$k++;
}
$k -= 1;
if $k > 0 {
push @factors, $p => $k;
}
if $n == 1 {
last;
}
if $n.is-prime {
push @factors, $n => 1;
last;
};
}
return @factors;
}
my $n = Int( @*ARGS[0] );
my @factors = prime-factorizatiion($n);
say @factors.map({ .key ~ "**" ~ .value }).join(" * ");
You can’t perform that action at this time.