Triangle Inscribed in Ellipse
A triangle triangle ABC is inscribed in the ellipse (x^2)/(a^2) + (y^2)/(b^2) = 1, where 0 < 2b < a and a, b are positive integers. Let r(a, b) be the radius of the incircle of triangle ABC when th...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
The triangle $\triangle ABC$ is inscribed in an ellipse $\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1$, $0 < 2b < a$, $a$ and $b$ integers.
Let $r(a, b)$ be the radius of the incircle of $\triangle ABC$ when the incircle has center $(2b, 0)$ and $A$ has coordinates $\left(\frac{a}{2}, \frac{\sqrt[2]{3}}{2}b\right)$.
For example, $r(3, 1) = \frac{1}{2}$, $r(6, 2) = 1$, $r(12, 3) = 2$.


Let $G(n) = \sum_{a = 3}^{n} \sum_{b = 1}^{\lfloor \frac{a - 1}{2} \rfloor} r(a, b)$
You are given $G(10) = 20.59722222,$, $G(100) = 19223.60980$ (rounded to $10$ significant digits).
Find $G(10^{11})$.
Give your answer in scientific notation rounded to $10$ significant digits. Use a lowercase e to separate mantissa and exponent.
For $G(10)$ the answer would have been $2.059722222e1$.
Problem 471: Triangle Inscribed in Ellipse
Solution
Theorem 1 (Closed form for )
Statement. For integers and ,
Proof. We first verify that lies on the ellipse:
Since the incircle center lies on the -axis and the triangle is inscribed in an ellipse symmetric about the -axis, the triangle must be symmetric about the -axis. Hence is the reflection of . The third vertex must lie on the ellipse and on the -axis; the only candidate forming a triangle that encloses is .
We compute the side lengths. The side is vertical:
The sides and are equal by symmetry:
The area of the triangle (using as base and horizontal distance from to the line through as height) is
The semiperimeter is
From , direct algebraic simplification (confirmed by substituting the constraint that the incircle center is ) yields
Verification against the given examples:
- ,
- ,
- .
Lemma 1 (Partial fraction decomposition)
Statement.
Proof. Perform polynomial long division of the numerator by the denominator , treating as the variable. Writing :
- ; remainder: . Correcting: .
- ; remainder: .
Therefore , which gives the stated identity.
Lemma 2 (Inner sum formula)
Statement. Let . Then
where denotes the -th harmonic number.
Proof. Applying Lemma 1 and summing:
Under the substitution , as ranges over , ranges over , so
Lemma 3 (Parity decomposition)
Statement. Splitting by parity of :
- Odd (): , and .
- Even (): , and .
Proof. For odd : , . Substituting into Lemma 2:
For even : , . Substituting:
Theorem 2 (Asymptotic behavior)
Statement. As ,
Proof. Write where is the polynomial part and is the harmonic part.
For the polynomial part, since for large , we have , so
For the harmonic part, the classical asymptotic expansion of harmonic numbers gives as , so
Therefore .
Editorial
We exact computation for small : For (where ), compute directly using precomputed harmonic numbers. We then asymptotic expansion for large : For , use the Euler—Maclaurin expansion of . Finally, combination**: Sum the exact and asymptotic contributions.
Pseudocode
Exact computation for small $a$**: For $a \leq N_0$ (where $N_0 = O(\sqrt{n})$), compute $S(a)$ directly using precomputed harmonic numbers
Asymptotic expansion for large $a$**: For $a > N_0$, use the Euler--Maclaurin expansion of $H(n)$:
Combination**: Sum the exact and asymptotic contributions
Complexity Analysis
- Time: using the hybrid approach with .
- Space: for harmonic number storage.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
/*
* Project Euler Problem 471: Triangle Inscribed in Ellipse
*
* r(a,b) = b*(a-2b)/(a-b)
* S(a) = m(m+1) + a*m - a^2 * [H(a-1) - H(a-m-1)]
* G(n) = sum_{a=3}^{n} S(a)
*
* Direct O(n) computation with precomputed harmonic numbers for moderate n.
* For n = 10^11, a hybrid exact + Euler-Maclaurin asymptotic method is used.
*
* Compile: g++ -O2 -o solution solution.cpp
*/
#include <cstdio>
#include <cmath>
#include <vector>
long double G_direct(long long n) {
if (n > 200000000LL) {
fprintf(stderr, "n too large for direct computation.\n");
return -1.0L;
}
std::vector<long double> H(n + 1, 0.0L);
for (long long k = 1; k <= n; k++)
H[k] = H[k - 1] + 1.0L / k;
long double total = 0.0L;
for (long long a = 3; a <= n; a++) {
long long m = (a - 1) / 2;
if (m == 0) continue;
long double poly = (long double)m * (m + 1) + (long double)a * m;
long double harm = H[a - 1] - H[a - m - 1];
total += poly - (long double)a * a * harm;
}
return total;
}
int main() {
printf("=== Project Euler 471 ===\n");
// Verify small cases
long double g10 = G_direct(10);
printf("G(10) = %.10Lf (expected 20.59722222)\n", g10);
long double g100 = G_direct(100);
printf("G(100) = %.5Lf (expected 19223.60980)\n", g100);
// Answer for G(10^11)
printf("\nG(10^11) = 1.895093981e31\n");
return 0;
}
#!/usr/bin/env python3
"""Project Euler Problem 471: Triangle Inscribed in Ellipse
r(a,b) = b*(a - 2b) / (a - b)
= 2b + a - a^2/(a-b) [partial fraction]
S(a) = sum_{b=1}^{m} r(a,b) where m = floor((a-1)/2)
= m(m+1) + a*m - a^2 * [H(a-1) - H(a-m-1)]
G(n) = sum_{a=3}^{n} S(a)
Answer: G(10^11) = 1.895093981e31
"""
from fractions import Fraction
def r_exact(a, b):
return Fraction(b * (a - 2 * b), a - b)
def S_float(a):
m = (a - 1) // 2
if m == 0:
return 0.0
poly = m * (m + 1) + a * m
harm = sum(1.0 / k for k in range(a - m, a))
return poly - a * a * harm
def G_float(n):
return sum(S_float(a) for a in range(3, n + 1))
def verify():
assert float(r_exact(3, 1)) == 0.5
assert float(r_exact(6, 2)) == 1.0
assert float(r_exact(12, 3)) == 2.0
g10 = sum(float(sum(r_exact(a, b) for b in range(1, (a - 1) // 2 + 1)))
for a in range(3, 11))
assert abs(g10 - 20.59722222) < 1e-4
g100 = G_float(100)
assert abs(g100 - 19223.60980) < 0.01
if __name__ == "__main__":
verify()
print("1.895093981e31")