(No Ratings Yet)

## Project Euler Problem 138 Solution

#### Problem Description

Consider the isosceles triangle with base length, b = 16, and legs, L = 17.

By using the Pythagorean theorem it can be seen that the height of the triangle, h = √(172 − 82) = 15, which is one less than the base length.

With b = 272 and L = 305, we get h = 273, which is one more than the base length, and this is the second smallest isosceles triangle with the property that h = b ± 1.

Find ∑ L for the twelve smallest isosceles triangles for which h = b ± 1 and b, L are positive integers.

#### Analysis

There are two ways to solve this problem. The first is to generate some triangles that match the requirements and search for an integer sequence; which we found. It turns out that one-half of every 6th iteration of the Fibonacci sequence, starting at the 9th, yields a solution for L. Namely: 34, 610, 10946, 196418, etc. or F(6n+3), n=1..12.

The second way, and actually more intuitive, is to solve for the Diophantine quadratic equation as:
(assuming x for b/2 to achieve integer coefficient for the resulting equation)

$2x\pm1 = \sqrt{L^2-x^2} , \\ (2x\pm1)^2 = L^2-x^2 , \\ 4x^2\pm4x+1 = L^2-x^2 , \\ 5x^2\pm4x+1-L^2 = 0$

Take a run over to: http://www.alpertron.com.ar/QUAD.HTM, and plug in the coefficients to calculate:

 5 x2 - y2 + 4 x +1 = 0

by Dario Alejandro Alpern

X0 = 0
Y0 = -1

and also:
X0 = 0
Y0 = 1

Xn+1 = P Xn + Q Yn + K
Yn+1 = R Xn + S Yn + L

P = -9
Q = -4
K = -4
R = -20
S = -9
L = -8


We verified this solution, but never had the need to implement it.

#### Solution

Runs < 1 second in Python.

from Euler import Fibonacci nt = 12   f = Fibonacci() print "Answer to PE138 =", sum( [f[6*n+3]/2 for n in range(1, nt+1)] )

See Sloane’s A007805.

## Discussion

### 5 Responses to “Project Euler Problem 138 Solution”

1. Clearly the constant parameter should be 2, not 1.

For 2 Dario’s website says there are no answers, care to explain how exactly you’ve verified that solution?

Posted by David | August 23, 2012, 2:46 PM
2. I used this method. Yet, my answer is still incorrect. Can you help me figure out why?

Posted by Jeffrey Robles | October 11, 2012, 1:11 AM
• The input to the solver is correct but the comment was 4x^2 ± 4x + 2 and had to correct it to 4x^2 ± 4x + 1. Sorry, that was probably throwing you off. It’s correct now.

Posted by Mike | October 29, 2012, 2:13 AM