Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- # 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 = 5^2. There exists exactly one Pythagorean
- # triplet for which a + b + c = 1000. Find the product a * b * c.
- for c in range(997, 2, -1):
- for b in range((999 - c) // 2 + 1, 1, -1):
- a = 1000 - (b + c)
- if a ** 2 + b ** 2 == c ** 2:
- print(a * b * c)
- exit(0)
- # 31875000
- # 6 function calls in 0.168 seconds
Add Comment
Please, Sign In to add comment