"""Build the segmented sieve used for validation (C source embedded below). Usage: python3 sieve_build.py # writes sieve.c next to this file and compiles ./sieve with gcc ./sieve 10000000000 401 1e9 1e10 > cp_1e9_1e10.txt Output columns at each of the 401 log-spaced checkpoints x in [1e9, 1e10]: x, theta(x), sum_{p<=x} log(1-1/p), sum_{p<=x} log(1-1/p^2), pi(x) (accumulators in binary128). Requires gcc and libquadmath. """ import os, subprocess SIEVE_C = r'''// Segmented sieve to LIMIT; at checkpoints x_j (sorted reals) output // theta(x), M(x)=sum_{p<=x} log(1-1/p), Q2(x)=sum_{p<=x} log(1-1/p^2), pi(x) // accumulators in __float128; per-term values in long double. #include #include #include #include #include #include int main(int argc,char**argv){ uint64_t LIMIT=strtoull(argv[1],0,10); int NC=atoi(argv[2]); double lo=atof(argv[3]), hi=atof(argv[4]); uint64_t *cp=malloc(sizeof(uint64_t)*NC); for(int j=0;jLIMIT) H=LIMIT; memset(seg,0,H-L+1); for(int k=0;kH) break; uint64_t s=(L+p-1)/p*p; if(s