# Reproduce redteam-0904-item0.md 6.1: certificate over the period at x=13. # C(x) = #holes in (x, x+H] - sum_{3<=p<=13} #{holes in window with hole == -2 mod p} P=[2,3,5,7,11,13]; W=1 for p in P: W*=p import math hole=bytearray(W) holes=0 for r in range(W): ok=True for p in P: if r%p==0: ok=False;break if ok: hole[r]=1; holes+=1 odd=[p for p in P if p!=2] print("x=13 W=%d holes=%d phi/W=%.9f twinconst prod(1-2/p)=%.9f"%(W,holes,holes/W, math.prod((1-2/p) for p in P))) B=sum(1/(p-1) for p in odd) print("B(13)=%.6f"%(B,)) # prefix arrays on doubled period for O(1) window counts H0=0 wh=[0]*(2*W+1) # holes wq=[[0]*(2*W+1) for _ in odd] # holes == -2 mod p for i in range(2*W): r=i%W wh[i+1]=wh[i]+hole[r] for j,p in enumerate(odd): wq[j][i+1]=wq[j][i]+(hole[r] and (r+2)%p==0) for H in (50,100,200,400): tot=0; pos=0; mx=None; mn=None for x in range(W): c=wh[x+H]-wh[x] for j in range(len(odd)): c-=wq[j][x+H]-wq[j][x] tot+=c if c>0: pos+=1 mx=c if mx is None or c>mx else mx mn=c if mn is None or c