am1x

seq002

Feb 15th, 2021 (edited)
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. import heapq
  2. import math
  3.  
  4. def appr_lim(n):
  5.     l10 = math.log(10.0)
  6.     x = 4 * n * math.log(n)
  7.     for _ in range(4):
  8.         x = (l10 + n * (math.log(9 * x) - 1)) / (l10 - n / x)
  9.     k = math.ceil(x)
  10.     #print("appr_lim", n, k)
  11.     assert (k > n)
  12.     assert (10**k > 10 * (9*k)**n)
  13.     return k
  14.    
  15. def sum_digits(n):
  16.     cnt = 0
  17.     res = 0
  18.     while n:
  19.         res += n % 10
  20.         cnt += 1
  21.         n //= 10
  22.        
  23.     return (res, cnt)
  24.  
  25. h = [(4, 2, 2)]
  26. lims = [1, 2, appr_lim(2)]
  27. seq = []
  28.  
  29. def step():
  30.     v = heapq.heappop(h)
  31.     x = v[0]
  32.     n = v[1]
  33.     a = v[2]
  34.    
  35.     sd = sum_digits(x)
  36.     if (sd[0] == a):
  37.         print(v)
  38.         seq.append(x)
  39.     if (1 * sd[1] < lims[n]):
  40.         heapq.heappush(h, ((a + 1)**n, n, a+1))
  41.     if (a == 2):
  42.         heapq.heappush(h, (2**(n+1), n+1, 2))
  43.         lims.append(appr_lim(n + 1))
  44.  
  45. while (len(seq) < 100):
  46.     step()
  47.  
  48.  
Add Comment
Please, Sign In to add comment