Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Finding divisors from factors

by danaj (Friar)
on Oct 08, 2014 at 18:44 UTC ( [id://1103203]=perlquestion: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use ntheory qw/:all/;
    my $n = 183092192580;
    print "Factors:  @{[factor($n)]}\n";
    print "Divisors: @{[divisors($n)]}\n";
    
  2. or download this
    sub divisors {
      my($n,@factors) = @_;
      my %divisors;
    ...
      @d;
    }
    sub powerset {@_ ? map { $_,[$_[0], @$_] } powerset(@_[1..$#_]) : [];}
    
  3. or download this
    sub divisors {
      my($n,@factors) = @_;
    
    ...
      my @divisors = sort {$a<=>$b} keys %all_factors;
      @divisors;
    }
    
  4. or download this
    sub divisors {
      my($n,@factors) = @_;
      my $sqrtn = int(sqrt($n));
    ...
      my @d = sort {$a<=>$b} keys %all_factors;
      @d, map { $_*$_ == $n ? () : int($n/$_) } reverse @d;
    }
    
  5. or download this
    #!/usr/bin/env perl
    use warnings;
    use strict;
    ...
      my @d = divisors($n,factor($n));
      print "$n @d\n";
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1103203]
Approved by ww
Front-paged by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-28 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found