use warnings; use strict; use integer; $|=1; print "Enter number: "; chomp(my $x = ); die "That's not my kind of number!" if $x=~/\D/ || $x/1 ne $x; if ($x <= 1) { print "$x\n"; exit } # get prime factors my %fact; my $fact = 2; do { ++$fact while $x/$fact*$fact != $x; ++$fact{$fact}; $x /= $fact; } while ($x > 1); # apply all combinations my @fact = 1; while (($fact,my $count) = each %fact) { my $index; @fact = map $_ * $fact**(++$index/@fact % ($count+1)), (@fact) x ($count+1); } print "@{[sort {$a<=>$b} @fact]}\n";