Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
- #a**2 + b**2 = c**2
- #For example, 3**2 + 4**2 = 9 + 16 = 25 = 52.
- #There exists exactly one Pythagorean triplet for which a + b + c = 1000.
- #Find the product abc.
- #Analysis
- # loop over a and b and then check whether a**2 + b**2 == (s - a - b)**2
- # From the condition a < b < c, we conclude that a<= (s-3)/3) and b < (s-a)/2)
- s = 1000
- for a in range(3,int((s-3)/3)+1):
- for b in range(a+1,int((s-a)/2)+1):
- c = s - a - b
- if c**2 == a**2 + b**2:
- print a,b,c
- print a*b*c
Advertisement
Add Comment
Please, Sign In to add comment