|
PROG
|
(Python)
N=3 # <== Adapt here
import heapq
sigma=1+2**N
h=[(sigma, 1, 2)]
nextcount=3
oldv, olds, oldl=0, 0, 0
while True:
(v, s, l)=heapq.heappop(h)
if v==oldv:
break
if v>=sigma:
sigma += nextcount**N
heapq.heappush(h, (sigma, 1, nextcount))
nextcount+=1
oldv, olds, oldl = v, s, l
v-=s**N ; s+=1 ; l+=1 ; v+=l**N
heapq.heappush(h, (v, s, l))
print("a(%d) = %d = sum(i^%d, i=%d..%d) = sum(i^%d, i=%d..%d)"%
(N, v, N, olds, oldl, N, s, l))
# Bert Dobbelaere, May 16 2021
|