in reply to Finding all divisors of an integer

Here's an implementation of gri6507's suggestion (using ordinary perl integers, not bigints):
use warnings; use strict; use integer; $|=1; print "Enter number: "; chomp(my $x = <STDIN>); 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";

Replies are listed 'Best First'.
Re^2: Finding all divisors of an integer
by Anonymous Monk on Jul 05, 2010 at 23:12 UTC
    oi? Newbie programer here.. dividing the number for primefactorization? sounds like this subroutine i cooked up to do my homework...
    sub primefactor ($) { my $number=shift; my @factors=(); for (my $i=2; $i<=$number;) { unless ($number%$i) { $number/=$i; push @factors, $i; } else {$i++} } @factors&&return(@factors); return($number); }