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