# Python code for OEIS A262713 # Michael S. Branicky, Aug 19 2021 # A262713 Numbers n such that sum of digits on n^2 is 10. 1 data = [8, 19, 35, 46, 55, 71, 80, 145, 152, 179, 190, 251, 332, 350, 361, 449, 451, 460, 548, 550, 649, 710, 800, 1450, 1520, 1790, 1900, 2510, 3320, 3500, 3610, 4490, 4499, 4510, 4600, 5480, 5500, 6490, 7100, 8000, 14500, 15200, 17900, 19000, 20249, 20251, 24499] from time import time time0 = time() def cond_final(s): return sum(map(int, s)) == 10 def cond_inter(s): return sum(map(int, s)) < 10 alst = [] digits = "0123456789" digset = set(digits) valid = set([""]) for e in range(1, 1001): print("Starting with", e, "digits; # to test =", len(valid), time()-time0) newvalid = set() for tstr in valid: for d in digset: dtstr = d + tstr dt = int(dtstr) remstr = str(dt**2)[-e:] if cond_inter(remstr): newvalid.add(dtstr) if cond_final(str(dt**2)): alst.append(dt) alst = sorted(set(alst)) print("# Terms =", len(alst)) print(" alst =", alst) print(" data =", data) with open('b262713.txt', 'w') as bfile: for n, an in enumerate(alst, start=1): bfile.write(f"{n} {an}\n") valid = newvalid