import math def inradius(a, b, c): s = (a + b + c) / 2 area = (s * (s - a) * (s - b) * (s - c)) inradius = area / s**2 return inradius def euler_195(): count = 0 limit = 1053779 limit2 = limit * limit for m in range(0, limit2): for n in range(1, m // 2 + 1): if math.gcd(m, n) == 1: # Generator function from wiki for 60 degree eisenstein # triangles. a = m**2 - m*n + n**2 b = 2*m*n - n**2 c = m**2 - n**2 gcd = math.gcd(a, b, c) a, b, c = a // gcd, b // gcd, c // gcd # if gcd == 3 and inradius(a, b, c) > limit2: # break if inradius(a / 3, b / 3, c / 3) > limit2: if n == 1: return count break if a == b and b == c: continue k = 1 while True: ir = inradius(a*k, b*k, c*k) if ir > limit2: break count += 1 k += 1 return count if __name__ == "__main__": solution = euler_195() print("e195.py: " + str(solution)) assert solution == 75085391