"""Directed elementary primes, harmonic increments, and fixed-point array operations.""" import argparse import math from bisect import bisect_left from decimal import Decimal as D,getcontext,ROUND_CEILING,ROUND_FLOOR from functools import lru_cache import numpy as np getcontext().prec=70 Q=2**30 PFX=10**15 CUT=250000 GAMMA_MIN=D('.5772') def dec(x):return x if isinstance(x,D) else D(str(x)) def guard(x):return D('1e-42')*(1+abs(x)) def ceil(x):return int(x.to_integral_value(rounding=ROUND_CEILING)) def up(x,scale=Q):return ceil((x+guard(x))*scale) def ceildiv(a,b):return (a+b-1)//b def mul(x,a): """Upward product x*a/Q, with integer arrays or scalars, no overflow.""" return a*(x//Q)+(a*(x%Q)+Q-1)//Q def getprimes(n): b=bytearray(b'\1')*(n+1);b[:2]=bytes(2) for p in range(2,math.isqrt(n)+1): if b[p]:b[p*p::p]=bytes((n-p*p)//p+1) return np.nonzero(np.asarray(b,dtype=np.uint8))[0].astype(np.int64) PR=getprimes(CUT) sum2=np.zeros(len(PR)+1,dtype='int64') sum1=sum2.copy() for a,ds in ((1,sum1),(2,sum2)): np.cumsum((PFX+PR[1:]-a-1)//(PR[1:]-a),out=ds[2:]) LOGCUT=D(CUT).ln() @lru_cache(maxsize=20000) def expv(t):return t.exp() def idxpr(t): val=expv(t) return int(np.searchsorted(PR, int((val+guard(val)).to_integral_value(rounding=ROUND_FLOOR)),side='right')) def interval_mass(a,b,prefix,first=0): """Upper ∑1/(p−k), exp(a)
=b:return D(0)
m=D(0)
if a