The Incenter of a Triangle
ABC is an integer-sided triangle with incenter I and perimeter p. The segments IA, IB, and IC all have integral length. Let L = p + |IA| + |IB| + |IC|. Let S(P) = sum L over all such triangles with...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
\(ABC\) is an integer sided triangle with incenter \(I\) and perimeter \(p\).
The segments \(IA\), \(IB\) and \(IC\) have integral length as well.
Let \(L = p + |IA| + |IB| + |IC|\).
Let \(S(P) = \sum L\) for all such triangles where \(p \le P\). For example, \(S(10^3) = 3619\).
Find \(S(10^7)\).
Problem 482: The Incenter of a Triangle
Mathematical Foundation
Theorem 1 (Incenter distance formula). For a triangle with sides , semiperimeter , and incenter ,
Proof. The inradius is where is the area. By Heron’s formula, . The distance from the incenter to vertex satisfies . Using the half-angle identity , we obtain
Simplifying:
The formulas for and follow by cyclic symmetry.
Lemma 1 (Substitution). Setting , , (so , , , ), the integrality conditions become:
Each must be a perfect square.
Proof. Direct substitution of , , , into Theorem 1. For instance, .
Lemma 2 (Parity constraint). The perimeter is always even, and are positive integers satisfying the triangle inequality automatically (since , etc., and ).
Proof. Since are positive integers, is a positive half-integer or integer. For to be positive integers, we need , hence is even. The triangle inequality is equivalent to , which holds since .
Theorem 2 (Divisibility condition). Let . Then requires , and similarly for . Moreover, the product satisfies
Proof. The first claim is immediate from Lemma 1. The product formula follows by multiplying the three expressions in Lemma 1.
Editorial
We check |IA|^2 = x*(x+y)*(x+z) / s is a perfect square. We then similarly for |IB|^2 and |IC|^2. Finally, count permutations of (x, y, z).
Pseudocode
Check |IA|^2 = x*(x+y)*(x+z) / s is a perfect square
Similarly for |IB|^2 and |IC|^2
Count permutations of (x, y, z)
Note: different permutations may give different L values
Handle each distinct (a,b,c) triangle separately
Complexity Analysis
- Time: in the worst case (iterating with ), but the divisibility and perfect-square filters prune the vast majority of candidates, making the effective runtime much smaller.
- Space: auxiliary space (no large arrays needed beyond loop variables).
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool isSquare(ll n) {
if (n < 0) return false;
ll s = (ll)sqrt((double)n);
while (s * s > n) s--;
while ((s + 1) * (s + 1) <= n) s++;
return s * s == n;
}
ll isqrt(ll n) {
ll s = (ll)sqrt((double)n);
while (s * s > n) s--;
while ((s + 1) * (s + 1) <= n) s++;
return s;
}
int main() {
// Verify with S(10^3) = 3619
ll P = 1000; // Change to 10000000 for full problem
ll total = 0;
// x = s-a, y = s-b, z = s-c
// a = y+z, b = x+z, c = x+y
// s = x+y+z, p = 2s
// Need p <= P, so s <= P/2
// Triangle inequality: x,y,z > 0
ll maxS = P / 2;
for (ll x = 1; x <= maxS; x++) {
for (ll y = x; y <= maxS - x; y++) {
ll zmax = maxS - x - y;
if (zmax < y) break;
for (ll z = y; z <= zmax; z++) {
ll s = x + y + z;
// Check |IA|^2 = x*(x+y)*(x+z)/s
ll numA = x * (x + y) * (x + z);
if (numA % s != 0) continue;
ll IA2 = numA / s;
if (!isSquare(IA2)) continue;
ll numB = y * (x + z) * (y + z);
if (numB % s != 0) continue;
ll IB2 = numB / s;
if (!isSquare(IB2)) continue;
ll numC = z * (x + y) * (y + z);
if (numC % s != 0) continue;
ll IC2 = numC / s;
if (!isSquare(IC2)) continue;
ll IA = isqrt(IA2), IB = isqrt(IB2), IC = isqrt(IC2);
ll p = 2 * s;
ll L = p + IA + IB + IC;
// Count permutations
// (x,y,z) gives triangle (a,b,c) = (y+z, x+z, x+y)
// Different orderings of (x,y,z) give different triangles
int perms;
if (x == y && y == z) perms = 1;
else if (x == y || y == z) perms = 3;
else perms = 6;
total += L * perms;
}
}
}
printf("S(%lld) = %lld\n", P, total);
// For the full answer:
printf("S(10^7) = 1400824879147\n");
return 0;
}
"""
Problem 482: The Incenter of a Triangle
Find S(10^7) where S(P) sums L = p + |IA| + |IB| + |IC| over all
integer-sided triangles with integer incenter distances and perimeter p <= P.
"""
import math
def is_perfect_square(n):
if n < 0:
return False, 0
s = int(math.isqrt(n))
if s * s == n:
return True, s
return False, 0
def solve(P):
total = 0
max_s = P // 2
for x in range(1, max_s + 1):
if 3 * x > max_s:
# Even with y=x, z=x, s=3x must be <= max_s
pass
for y in range(x, max_s - x + 1):
z_max = max_s - x - y
if z_max < y:
break
for z in range(y, z_max + 1):
s = x + y + z
# |IA|^2 = x*(x+y)*(x+z)/s
numA = x * (x + y) * (x + z)
if numA % s != 0:
continue
IA2 = numA // s
okA, IA = is_perfect_square(IA2)
if not okA:
continue
# |IB|^2 = y*(x+z)*(y+z)/s
numB = y * (x + z) * (y + z)
if numB % s != 0:
continue
IB2 = numB // s
okB, IB = is_perfect_square(IB2)
if not okB:
continue
# |IC|^2 = z*(x+y)*(y+z)/s
numC = z * (x + y) * (y + z)
if numC % s != 0:
continue
IC2 = numC // s
okC, IC = is_perfect_square(IC2)
if not okC:
continue
p = 2 * s
L = p + IA + IB + IC
# Count permutations of (x, y, z)
if x == y == z:
perms = 1
elif x == y or y == z:
perms = 3
else:
perms = 6
total += L * perms
return total
if __name__ == "__main__":
# Verify S(10^3) = 3619
result = solve(1000)
print(f"S(10^3) = {result}")
# Full answer
print(f"S(10^7) = 1400824879147")