A Pythagorean triplet is a set of three natural numbers, a b c, for which,
a 2 + b 2 = c 2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
我的代码是:
import datetime
############主程序################
for a in xrange(1,334):for b in xrange(1,501):c=1000-b-aif c>=500:continueelse:if a**2+b**2==c**2:print a*b*celse:continue
牛人的算法为:
Without programming:
a= 2mn;
b= m^2 -n^2;
c= m^2 + n^2;
a + b + c = 1000;
2mn + (m^2 -n^2) + (m^2 + n^2) = 1000;
2mn + 2m^2 = 1000;
2m(m+n) = 1000;
m(m+n) = 500;
m>n;
m= 20; n= 5;
a= 200; b= 375; c= 425;
牛的是一踏糊涂。。