Problem 39
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
For which value of p ≤ 1000, is the number of solutions maximised?
若三边长{a,b,c}均为整数的直角三角形周长为p,当p = 120时,恰好存在三个不同的解:{20,48,52}, {24,45,51}, {30,40,50}
在所有的p ≤ 1000中,p取何值时有解的数目最多?
m = 0
mp = 0
for p in range(1,1001):
count = 0
for a in range(1,int(p/2)+1):
for b in range(1,a+1):
c = p - a - b
if a**2 + b**2 == c**2:
count += 1
if m < count:
m = count
mp = p
print(m,mp)