def pentagonal(n): return n * (3 * n - 1) // 2 def euler_044(): n = 10000 p = [pentagonal(n) for n in range(1, n)] p_set = set(p) for i in range(1, n): for j in range(i + 1, n): if p[i - 1] + p[j - 1] in p_set and p[j - 1] - p[i - 1] in p_set: d = pentagonal(j) - pentagonal(i) s = d # print("i = {}, j = {}, d = {}.".format(i, j, d)) return s if __name__ == "__main__": print("e044.py: " + str(euler_044())) assert(euler_044() == 5482660)