欧拉计划(python) problem 9


Special Pythagorean triplet

Problem 9

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,

a2 + b2 = c2

For example, 32 + 42 = 9 + 16 = 25 = 52.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.


python code:


for i in range(1,1000):
id=0
for j in range(i,1000):
c=1000-i-j
if c<=0:
continue
else:
if i*i+j*j!=c*c:
continue
else:
print(i*j*c)
id=1
break
if id==1:
break


result : 31875000

time : <1s


评论关闭