# Python program for OEIS A354466 # A354466 Numbers k such that the decimal expansion of the sum of the reciprocals of the digits of k starts with the digits of k in the same order. 0 data = [1, 13, 145, 153, 1825, 15789, 16666, 21583, 216666, 2416666, 28428571] # (Python) from sympy import isprime from fractions import Fraction from itertools import count, islice, combinations_with_replacement as mc def numwithdigs(d): if d == 0: return 0 yield from ("".join(m) for m in mc("123456789", d)) def agen(verbose=False): for digs in count(1): found = set() for k in numwithdigs(digs): rs = sum(Fraction(1, int(d)) for d in k) if rs.numerator < rs.denominator: continue rss = str(int(rs*10**(2*digs-1))).replace(".", "")[:digs] if "0" not in rss and "".join(sorted(rss)) == k: found.add(int(rss)) yield from sorted(found) if verbose: print("...", d, time()-time0) print(list(islice(agen(), 16))) # ~~~~ print(data) assert data == list(islice(agen(), len(data))) print() from time import time time0 = time() alst = [] for n, an in enumerate(agen(), 1): alst.append(an) print(n, an, len(str(alst))-2, time()-time0) print(" ", alst) print(" ", data)