Problem 39
14 March 2003
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.
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p
1000, is the number of solutions maximised?
def fun39():
result = (0, 0)
#a**2+b**2=c**2,a<=b
(a,b,c)=(1,2,3)
for p in range(4, 1000):
count = 0
for a in range(1, p/3):
t = (a**2)%(p-a)
if t != 0:
continue
else:
t = (a**2)/(p-a)
if (t+p-a)%2 == 0:
(b,c) = ((p-a-t)/2, (t+p-a)/2)
if b < a:
break
else:
count += 1
print a,b,c
if count > result[1]:
result = (p, count)
return result
answer is 840, 共有8组
time:0.125
阅读(419) | 评论(0) | 转发(0) |