#A136317 a(n) integers with digit sum a(n); a(n+1) is the smallest integer > a(n). #Python 2.7 - John Cerkan #takes about a minute on this pentium core def digsum(n): asum = n%10 while n > 0: n = n // 10 asum += n % 10 return asum an = [1,2] n = 3 inx = 1 total = 2 cnt = 1 while len(an) < 10001: # number of terms to print when done dsum = digsum(n) if dsum == total: an.append(n) cnt += 1 if cnt == total: cnt = 0 inx += 1 total = an[inx] if total > 100: n = int(str(len(an)%9) + str(len(an)//9)) else: n += 1 else: n += 1 elif dsum < total: a1 = (total-dsum) // 9 a = max((total-dsum),(10**a1)-1) n += a else: n += 1 for i in range(len(an)): print str(i+1) + " " + str(an[i])