Python program from Ron Reble, July 18 2017, who says: The MaxN value is the first value that the program doesn't check. If you want a 10000-line B file, good luck: after translating to C++ and tuning, it's a half-day run on BitTwiddler. But a(1000)=180055; the python program can probably get that far. #!/usr/bin/python # %I A110081 # %S 1 7 25 31 37 73 79 85 97 103 # 193 241 253 271 313 319 337 343 361 517 # 553 661 703 721 727 733 745 751 # %N Integers n such that the digit set D = (0,1,-n) used in base 3 # expansions of the form Sum_{ -N < j < infty} d_j 3^{-j}, # all d_j in D, can represent all real numbers. # %A njas, based on correspondence from R. K. Guy and Jeff Lagarias, # Aug 31 2005 # For N in the sequence: # N is 1 mod 3. (Matula Lemma 2) # If N is 4 mod 6, you can't represent N/2, so N is 1 mod 6. # N isn't 3 mod 8 and isn't 0,3,9 mod 13. (Matula theorem 5) # If N written in ternary begins "12", you can't represent 2. # For N == 1 mod 6 but not in the sequence: # There's an unrepresentable value in [0,N/6]. (Matula eqn (10)) # If 3A or 3A+1 is unrepresentable, then A is unrepresentable: # the least positive unrepresentable value is 2 mod 3. # For N in the sequence, print: # N, a longest value, and its representation. # "Longest value" means that, for values between 2 and N/6, this # value has a longest representation. # For N not in the sequence, but not eliminated by the above modular # and "12" criteria, print: # "#", N, and the least positive 2-mod-3 unrepresentable value. PrintNonElements = False PrintLongest = False MaxN = 180056 # return None if there's no representation of val def getRep(nn, val): cycleset = {val} v2 = val repstr = "" while v2 != 0: v2m3 = v2 % 3 if v2m3 == 0: repstr = "0" + repstr elif v2m3 == 1: repstr = "1" + repstr # v2 -= 1 # The "v2 /= 3" below takes care of this. else: repstr = "x" + repstr v2 += nn v2 /= 3 if v2 in cycleset: return None # no representation cycleset.add(v2) return repstr gapst = 1*3+2 # the next "12" gap gapnd = 2*3 for NN in range(1, MaxN, 6): if NN >= gapst: if NN < gapnd: continue gapst *= 3 gapnd *= 3 # mod 8, 13 criteria if (NN % 8) == 3: continue m13 = NN % 13 if (m13 == 0) or (m13 == 3) or (m13 == 9): continue # check 2 mod 3 values up to NN/6 longval = 1 longrep = "1" good = True for val in range(2, NN/6 + 1, 3): repstr = getRep(NN, val) if repstr == None: good = False break elif len(longrep) < len(repstr): longval = val longrep = repstr if good: if PrintLongest: print NN, longval, longrep else: print NN else: if PrintNonElements: print "#", NN, val --- end of program ---