And here is the simplest way I would solve this:
#!/usr/bin/perl -w
use strict;
use Algorithm::Loops 'NestedLoops';
my %f = ( 2 => 2, 3 => 1, 5 => 1, 11 => 1, 277412413 => 1 );
my @f = sort { $b <=> $a } keys %f;
my @d = NestedLoops(
[ map [ 0 .. $f{$_} ], @f ],
sub {
my $p = 1;
for my $i ( 0 .. $#_ ) {
$p *= $f[$i]
for 1..$_[$i];
}
return $p;
},
);
@d = sort { $a <=> $b } @d;
print "Divisors: @d\n";
Divisors: 1 2 3 4 5 6 10 11 12 15 20 22 30 33 44 55 60 66 110 132 165
+220 330 660 277412413 554824826 832237239 1109649652 1387062065 16644
+74478 2774124130 3051536543 3328948956 4161186195 5548248260 61030730
+86 8322372390 9154609629 12206146172 15257682715 16644744780 18309219
+258 30515365430 36618438516 45773048145 61030730860 91546096290 18309
+2192580
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|