[libmath-prime-util-perl] 15/43: give twin_prime_count a much denser table (92 vs. 5)
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:53:06 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.40
in repository libmath-prime-util-perl.
commit 3b566e5e04795d5b198ac8be7a14e042f6d88c76
Author: Dana Jacobsen <dana at acm.org>
Date: Fri Mar 21 14:42:43 2014 -0700
give twin_prime_count a much denser table (92 vs. 5)
---
util.c | 47 ++++++++++++++++++++++++++++++++++++-----------
1 file changed, 36 insertions(+), 11 deletions(-)
diff --git a/util.c b/util.c
index 8249387..b03c4e2 100644
--- a/util.c
+++ b/util.c
@@ -859,23 +859,48 @@ UV nth_prime(UV n)
return ( (segbase*30) + p );
}
+#if BITS_PER_WORD < 64
+static const UV twin_steps[] =
+ {58980,48427,45485,43861,42348,41457,40908,39984,39640,39222,
+ 373059,353109,341253,332437,326131,320567,315883,312511,309244,
+ 2963535,2822103,2734294,2673728,
+ };
+static const unsigned int twin_num_exponents = 3;
+static const unsigned int twin_last_mult = 4; /* 4000M */
+#else
+static const UV twin_steps[] =
+ {58980,48427,45485,43861,42348,41457,40908,39984,39640,39222,
+ 373059,353109,341253,332437,326131,320567,315883,312511,309244,
+ 2963535,2822103,2734294,2673728,2626243,2585752,2554015,2527034,2501469,
+ 24096420,23046519,22401089,21946975,21590715,21300632,21060884,20854501,20665634,
+ 199708605,191801047,186932018,183404596,180694619,178477447,176604059,174989299,173597482,
+ 1682185723,1620989842,1583071291,1555660927,1534349481,1517031854,1502382532,1489745250, 1478662752,
+ 14364197903,13879821868,13578563641,13361034187,13191416949,13053013447,12936030624,12835090276, 12746487898,
+ 124078078589,120182602778,117753842540,115995331742,114622738809,113499818125,112551549250,111732637241,111012321565,
+ 1082549061370,1050759497170,1030883829367,1016473645857,1005206830409,995980796683,988183329733,981441437376,975508027029,
+ 9527651328494,
+ };
+static const unsigned int twin_num_exponents = 10;
+static const unsigned int twin_last_mult = 2; /* 2e16 */
+#endif
+
UV twin_prime_count(UV beg, UV end)
{
unsigned char* segment;
UV sum = 0;
- if (beg <= 2) {
-#if BITS_PER_WORD == 64
- if(end>=UVCONST(10000000000000)){sum=15834664872;beg=10000000000000;}
- else if(end>=UVCONST( 1000000000000)){sum= 1870585220;beg= 1000000000000;}
- else if(end>=UVCONST( 100000000000)){sum= 224376048;beg= 100000000000;}
- else if(end>=UVCONST( 10000000000)){sum= 27412679;beg= 10000000000;}
- else if(end>=UVCONST( 1000000000)){sum= 3424506;beg= 1000000000;}
-#else
- if(end>=UVCONST( 1000000000)){sum= 3424506;beg= 1000000000;}
-#endif
+ /* First use the tables of #e# from 1e7 to 2e16. */
+ if (beg <= 3 && end >= 10000000) {
+ UV mult, exp, step = 0, base = 10000000;
+ for (exp = 0; exp < twin_num_exponents && end >= base; exp++) {
+ for (mult = 1; mult < 10 && end >= mult*base; mult++) {
+ sum += twin_steps[step++];
+ beg = mult*base;
+ if (exp == twin_num_exponents-1 && mult >= twin_last_mult) break;
+ }
+ base *= 10;
+ }
}
-
if (beg <= 3 && end >= 3) sum++;
if (beg <= 5 && end >= 5) sum++;
if (beg < 11) beg = 7;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git
More information about the Pkg-perl-cvs-commits
mailing list