2008年(47)
分类:
2008-11-12 12:31:55
A Pythagorean triplet is a set of three natural numbers, a b
c, for which,
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
由a2 + b2 = c2知道,a, b, c可以构成三角形,我们令a<=b<=c,则a的取值范围为[1,333]
又有a2 + b2 = c2,则a2=(b+c)(c-b), a + b + c = 1000, 得到a2=(1000-a)*(c-b)
这样我们先可以得到符合条件的a, 在进一步得到b, c
def fun9():
a = -1
b = -1
c = -1
for a in range(1, 334):
bc = 1000-a
s = a**2
if s%bc == 0:
cb = s/bc
if (bc+cb)%2 == 0:
c = (bc+cb)/2
b = bc - c
if (c>0) and (b>0):
print a, b, c, a*b*c
return a*b*c
answer = 31875000