mini = 8962
maxi = 9189

def is_happy(n):
    table = list()
    while len(str(n))>1:
        n = str(sum([int(i)**2 for i in str(n)]))
        if n in table:
            break
        else:
            table.append(n)
    return n=="1"

solution = list()
for i in range(mini, maxi+1):
    if is_happy(i):
        solution.append(i)

print(solution)