Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: Odd error message

by shadowsong (Pilgrim)
on Sep 16, 2015 at 19:27 UTC ( [id://1142234]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Odd error message
in thread Odd error message

robert44444uk,

No problem. I had another crack at it using what I thought would entail slightly less overhead:

#!/usr/bin/perl -slw use strict; use Math::GMPz qw(:mpz); my @crt = qw( 68083089690 131417981310 36415643880 51194848320 106157886450 30083217780 154569039240 55922110860 18269362650 12688113900 108608348310 2163950250 195808561410 89629478400 35610139950 164950347870 104015130450 198396537570 4751926410 91952139510 187872373920 182291125170 144638376960 149365639500 45991448580 94402601370 142813754160 69142506510 132477398130 164144843940 ); my $beg = shift || 91960283; my $end = shift || 300000000; my $fact = 2*3*5*7*11*13*17*19*23*29*31; my $target = 650; open FH, '>', 'prime_dump.txt' or die "could not open file: $!\n"; for my $i ($beg .. $end) { for (@crt) { my $num = $fact*$i+$_; my $start = Rmpz_init(); my_prev_prime_p($start,$num); my $end = Rmpz_init(); Rmpz_nextprime($end, Math::GMPz->new( +$num)); my $gap = Rmpz_init(); Rmpz_sub($gap, $end, $start); print FH "$i $_ $gap ",$gap/log($num) if $gap > $target; } } close FH; # ---------------------------------------------------------------- # Find probable prime that precedes param2 via Rmpz_probab_prime_p # ---------------------------------------------------------------- sub my_prev_prime_p { my ($rop,$num) = (shift,shift); my $i = $num; Rmpz_set_d($rop,2); # default param1 to 2 (the smallest prime) while ($i > 2) { $i--; next unless $i % 2; # evaluate odd numbers only Rmpz_set_str($rop,$i,10) || return if Rmpz_probab_prime_p(Math +::GMPz->new($i),10); } return; } __END__

However, it performed just as bad as your attempts using next_prime and prev_prime if not worse...

We'd be very keen to see how/if you managed to get your script to perform better.

Best of luck (and God speed)
shadowsong

Replies are listed 'Best First'.
Re^4: Odd error message
by robert44444uk (Acolyte) on Sep 20, 2015 at 18:47 UTC

    Thank you Shadowsong. I have had to concentrate on work this last week. When this settles down I will have another go at this program.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-24 18:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found