Almost Equilateral Triangles¶
There are two cases to consider: triangles with side lengths $(k, k, k-1)$ (perimeter $3k-1$) and triangles with side lengths $(k, k, k+1)$ (perimeter $3k+1$). If we apply Heron's formula, we can compute the areas of these triangles just from the side lengths. For the first case, $$A = \sqrt{s(s-k)^2(s-k+1)} = (s-k)\sqrt{s(s-k+1)}$$ where $s = \frac{1}{2}(3k-1)$ ($s$ is the semiperimeter); for the second case, $$A = \sqrt{s(s-k)^2(s-k-1)} = (s-k)\sqrt{s(s-k-1)}$$ where $s = \frac{1}{2}(3k+1)$.
In both cases, we are looking for values of $k$ such that $A$ is an integer - such triangles are called almost-equilateral Heronian triangles.
Consider the first case - for $A$ to be an integer, $s(s-k+1)$ must be a square number. With a little bit of algebra, this can be formulated as a Diophantine problem in terms of $k$. $$4z^2 = 3k^2 + 2k - 1$$ Note that we don't really care about the value of $z$ here (beyond being integral) - we just care about what values of $k$ work.
var('k,z')
sols = solve_diophantine(3*k^2 + 2*k - 1 == 4*z^2, k)
sols
[-1/3*(780*sqrt(3) + 1351)^t*(4*sqrt(3) + 7) + 1/3*(-780*sqrt(3) + 1351)^t*(4*sqrt(3) - 7) - 1/3, -1/3*(780*sqrt(3) + 1351)^t*(56*sqrt(3) + 97) + 1/3*(-780*sqrt(3) + 1351)^t*(56*sqrt(3) - 97) - 1/3, -1/3*(780*sqrt(3) + 1351)^t*(780*sqrt(3) + 1351) + 1/3*(-780*sqrt(3) + 1351)^t*(780*sqrt(3) - 1351) - 1/3, 1/3*(780*sqrt(3) + 1351)^t*(209*sqrt(3) + 362) - 1/3*(-780*sqrt(3) + 1351)^t*(209*sqrt(3) - 362) - 1/3, 1/3*(780*sqrt(3) + 1351)^t*(sqrt(3) + 2) - 1/3*(-780*sqrt(3) + 1351)^t*(sqrt(3) - 2) - 1/3, 1/3*(780*sqrt(3) + 1351)^t*(15*sqrt(3) + 26) - 1/3*(-780*sqrt(3) + 1351)^t*(15*sqrt(3) - 26) - 1/3]
(See problem 45 for discussion on solving Diophantine equations like this.)
We get several parametric formulas for $k$, but we only care about side lengths that are positive (duh) and that generate triangles with perimeters below 1000000000. ($k=1$ is also a solution to the Diophantine equation - we exclude it since a 1-1-0 triangle is obviously degenerate
evals = {expr(t=i).simplify_full() for expr in sols for i in range(-5, 5)}
sides = {k for k in evals if k > 1 and 3*k - 1 <= 1000000000}
sides
{17, 241, 3361, 46817, 652081, 9082321, 126500417}
With our side lengths found, we can easily compute the perimeters.
perimeters = {3*k - 1 for k in sides}
For the second case, the Diophantine problem is very similar - just one sign change. (As above, $k=1$ is excluded since a 1-1-2 triangle is degenerate.)
sols = solve_diophantine(3*k^2 - 2*k - 1 == 4*z^2, k)
evals = {expr(t=i).simplify_full() for expr in sols for i in range(-5, 5)}
sides = {k for k in evals if k > 1 and 3*k + 1 <= 1000000000}
sides
{5, 65, 901, 12545, 174725, 2433601, 33895685}
Now we just add those perimeters to get our final answer.
perimeters |= {3*k + 1 for k in sides}
sum(perimeters)
518408346
Relevant sequences¶
- Side lengths in the first case: A103772
- Side lengths in the second case: A103974
- The union of the two cases: A120893
Copyright (C) 2025 filifa¶
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license and the BSD Zero Clause license.