sub get_nof2 { return scalar @{ divisors(+shift) }; } { my $D; sub divisors { my $n = shift; foreach my $d ( 2 .. sqrt($n) ) { unless ( $n % $d ) { my $div = $n / $d; unless ( defined $D->{$div} ) { $D->{$div} = divisors($div); } return $D->{$n} = [ uniq( @{ $D->{$div} }, map { $d * $_ } @{ $D->{$div} } + ) ]; } } return $D->{$n} = [ 1, $n ]; }
In reply to Re: Learning math and efficient algorithms using perl
by artist
in thread Learning math and efficient algorithms using perl
by andreas1234567
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |