Problem 138

completed January 29, 2012

Comments

Obviously, this problem was about Pythagorean triples. What is cool about this problem is that when m and n are used to generate the triples (m > n), the value of n for the next triple is the value of m for the previous! Also, the next value of m is about 4 times larger than the previous.

Results

Script runs in under 1 second!

Code

L = []
m = 0
n = 1
while len(L) < 12:
	m += 1
	a = m**2 - n**2
	b = 2*m*n
	c = m**2 + n**2
	if 2*a == b + 1 or 2*a == b - 1 or 2*b == a + 1 or 2*b == a - 1:
		L.append(c)
		print m, n, len(L)
		n = m
		m = int(m*4.2)

print sum(L)