It is easily proved that no equilateral triangle exists with integral length sides and integral area. However, the almost equilateral triangle 5-5-6 has an area of 12 square units.
We shall define an almost equilateral triangle to be a triangle for which two sides are equal and the third differs by no more than one unit.
Find the sum of the perimeters of all almost equilateral triangles with integral side lengths and area and whose perimeters do not exceed one billion (1,000,000,000).
In [1]:
a, b, p, s = 1, 0, 0, 0
while p <= 10**9:
s += p
a, b = 2*a + 3*b, a + 2*b
p = 4*a*a
a, b, p = 1, 1, 0
while p <= 10**9:
s += p
a, b = 2*a + 3*b, a + 2*b
p = 2*a*a
print(s)
Discussion:
In [ ]: