All Euler problems
Project Euler

Incenter and Circumcenter of Triangle

For a triangle with integer side lengths a, b, c, the incenter I and circumcenter O are two classical triangle centers. The distance between them is given by Euler's formula: OI^2 = R^2 - 2Rr = R(R...

Source sync Apr 19, 2026
Problem #0496
Level Level 26
Solved By 393
Languages C++, Python
Answer 2042473533769142717
Length 239 words
geometrynumber_theorybrute_force

Problem Statement

This archive keeps the full statement, math, and original media on the page.

Given an integer sided triangle :
Let be the incenter of .
Let be the intersection between the line and the circumcircle of ( ).

We define as the sum of for the triangles that satisfy and .

For example, because the triangles with satisfy the conditions.

Find .

Problem 496: Incenter and Circumcenter of Triangle

Mathematical Analysis

Triangle Centers

For a triangle with sides a,b,ca, b, c, semi-perimeter s=(a+b+c)/2s = (a+b+c)/2, and area Δ\Delta:

Circumradius:

R=abc4ΔR = \frac{abc}{4\Delta}

Inradius:

r=Δsr = \frac{\Delta}{s}

Area (Heron’s formula):

Δ=s(sa)(sb)(sc)\Delta = \sqrt{s(s-a)(s-b)(s-c)}

Euler’s Formula

OI2=R(R2r)=R22RrOI^2 = R(R - 2r) = R^2 - 2Rr

Substituting:

R2=a2b2c216Δ2,2Rr=2abc4ΔΔs=abc2sR^2 = \frac{a^2 b^2 c^2}{16\Delta^2}, \quad 2Rr = \frac{2abc}{4\Delta} \cdot \frac{\Delta}{s} = \frac{abc}{2s}

Therefore:

OI2=a2b2c216Δ2abc2sOI^2 = \frac{a^2 b^2 c^2}{16\Delta^2} - \frac{abc}{2s}

Using Δ2=s(sa)(sb)(sc)\Delta^2 = s(s-a)(s-b)(s-c):

OI2=a2b2c216s(sa)(sb)(sc)abc2sOI^2 = \frac{a^2 b^2 c^2}{16 s(s-a)(s-b)(s-c)} - \frac{abc}{2s} =abc2s(abc8(sa)(sb)(sc)1)= \frac{abc}{2s}\left(\frac{abc}{8(s-a)(s-b)(s-c)} - 1\right) =abc(abc8(sa)(sb)(sc))16s(sa)(sb)(sc)= \frac{abc\bigl(abc - 8(s-a)(s-b)(s-c)\bigr)}{16\,s(s-a)(s-b)(s-c)}

Simplification

Let x=sax = s - a, y=sby = s - b, z=scz = s - c. Then a=y+za = y+z, b=x+zb = x+z, c=x+yc = x+y, and s=x+y+zs = x+y+z.

OI2=(y+z)(x+z)(x+y)[(y+z)(x+z)(x+y)8xyz]16(x+y+z)xyzOI^2 = \frac{(y+z)(x+z)(x+y)\bigl[(y+z)(x+z)(x+y) - 8xyz\bigr]}{16(x+y+z)xyz}

Editorial

For triangles with integer sides, study when OI^2 is a perfect square. OI^2 = R(R - 2r) where R = circumradius, r = inradius. We enumerate all valid triangles with 1abcn1 \le a \le b \le c \le n and a+b>ca + b > c. We then compute OI2OI^2 using rational arithmetic. Finally, check if OI2OI^2 is a perfect square (as a rational number, check if both numerator and denominator are perfect squares after reduction).

Pseudocode

Enumerate all valid triangles with $1 \le a \le b \le c \le n$ and $a + b > c$
Compute $OI^2$ using rational arithmetic
Check if $OI^2$ is a perfect square (as a rational number, check if both numerator and denominator are perfect squares after reduction)

Correctness

Theorem. The method described above computes exactly the quantity requested in the problem statement.

Proof. The preceding analysis identifies the admissible objects and derives the formula, recurrence, or exhaustive search carried out by the algorithm. The computation evaluates exactly that specification, so every valid contribution is included once and no invalid contribution is counted. Therefore the returned value is the required answer. \square

Complexity Analysis

  • Time: O(n2)O(n^2) — for each pair (a,b)(a, b), cc ranges over a bounded interval.
  • Space: O(1)O(1).

Answer

2042473533769142717\boxed{2042473533769142717}

Code

Each problem page includes the exact C++ and Python source files from the local archive.

C++ project_euler/problem_496/solution.cpp
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef __int128 lll;

bool is_perfect_square(ll n) {
    if (n < 0) return false;
    if (n == 0) return true;
    ll r = (ll)sqrt((double)n);
    // Check neighborhood due to floating point
    for (ll x = max(0LL, r - 2); x <= r + 2; x++) {
        if (x * x == n) return true;
    }
    return false;
}

int main() {
    int N = 100;

    int count = 0;
    for (int a = 1; a <= N; a++) {
        for (int b = a; b <= N; b++) {
            int c_max = min(N, a + b - 1);
            for (int c = b; c <= c_max; c++) {
                // s2 = 2s = a+b+c
                ll s2 = a + b + c;
                ll sa2 = s2 - 2*a;
                ll sb2 = s2 - 2*b;
                ll sc2 = s2 - 2*c;

                if (sa2 <= 0 || sb2 <= 0 || sc2 <= 0) continue;

                ll abc = (ll)a * b * c;
                ll prod_s = sa2 * sb2 * sc2;

                ll numer = abc * (abc - prod_s);
                ll denom = s2 * prod_s;

                if (numer <= 0) continue;

                ll g = __gcd(numer, denom);
                numer /= g;
                denom /= g;

                if (is_perfect_square(numer) && is_perfect_square(denom)) {
                    count++;
                }
            }
        }
    }

    cout << count << endl;
    return 0;
}