Project Euler Problem 513

ABC is an integral sided triangle with sides a le b le c.

Project Euler Problem 513

Solution

Answer: 2925619196

Using Apollonius’ theorem for the median to side $c$,

$$m_c^2=\frac{2a^2+2b^2-c^2}{4},$$

we require

$$2a^2+2b^2-c^2$$

to be a perfect square divisible by $4$.

A key observation is that $c$ must be even, so write $c=2k$.

Setting

$$u=\frac{a+b}{2},\qquad v=\frac{b-a}{2},$$

the condition becomes

$$u^2+v^2 = k^2 + m^2.$$

This reduces the problem to counting equal sums of two squares under the triangle constraints

$$u+v \le 2k < 2u.$$

Using the standard parametrization of equal sums of two squares and an $O(n^2)$-style enumeration over primitive generators (with multiplicities), the computation reproduces the checks

$$F(10)=3,\qquad F(50)=165,$$

and for $n=100000$ gives:

Answer: 1897703