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

Re: How not to do prime factorization

by atcroft (Abbot)
on Jun 30, 2015 at 16:46 UTC ( [id://1132640]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    perl -Mstrict -Mwarnings -le 'my $n = shift or die qq{Requires 1 numbe
    +r argument.}; my $o = $n; my @f = (); my $i = 2; while ( $n % $i == 0
    + ) { push @f, $i; $n /= $i; } $i++; while ( $n >= $i ) { while ( $n %
    + $i == 0 ) { push @f, $i; $n /= $i; } if ( $n > $i ) { $i += 2; } } p
    +rint $o, q{ = }, join q{*}, @f;'
    
  2. or download this
    $ for number in 3 31 314 3142 31416 314159 3141593 31415927 314159265 
    +3141592654 31415926536 ; do time -p perl -Mstrict -Mwarnings -le 'my 
    +$n = shift or die qq{Requires 1 number argument.}; my $o = $n; my @f 
    += (); my $i = 2; while ( $n % $i == 0 ) { push @f, $i; $n /= $i; } $i
    +++; while ( $n >= $i ) { while ( $n % $i == 0 ) { push @f, $i; $n /= 
    +$i; } if ( $n > $i ) { $i += 2; } } print $o, q{ = }, join q{*}, @f;'
    +  $number ; done
    3 = 3
    ...
    real 47.17
    user 47.03
    sys 0.03
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1132640]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-20 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found