|
PROG
|
(Python)
import heapq
def ispal(n): s = str(n); return s == s[::-1]
def afind():
print("0, ") # special case
N, T = 4, 1 # power, min number of terms
sigma = sum(i**N for i in range(1, T+1))
h = [(sigma, 1, T)]
nextcount = T + 1
while True:
(v, s, l) = heapq.heappop(h)
if ispal(v): print(f"{v}, [= Sum_{{i = {s}..{l}}} i^{N}]")
if v >= sigma:
sigma += nextcount**N
heapq.heappush(h, (sigma, 1, nextcount))
nextcount += 1
v -= s**N; s += 1; l += 1; v += l**N
heapq.heappush(h, (v, s, l))
|