def euler_136(): n = 10**8 threshold = 50*10**6 lookup = [0 for _ in range(0, threshold)] firstpositivestart = 1 for x in range(1, n): firstpositive = False for dxy in range(firstpositivestart, x // 2 + 1): z = x - 2 * dxy if z <= 0: break y = x - dxy xyz = x*x - y*y - z*z if xyz <= 0: continue # Start when xyz is already greater than 0. if not firstpositive: firstpositivestart = dxy firstpositive = True # If xyz is greater than threshold there are no more solutions. if xyz >= threshold: break lookup[xyz] += 1 r = 0 for v in lookup: if v == 1: r += 1 return r if __name__ == "__main__": solution = euler_136() print("e136.py: " + str(solution)) assert solution == 2544559