banovski

Project Euler, Problem #9, Python

Feb 6th, 2022 (edited)
1,406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. #! /usr/bin/env python3
  2.  
  3. # A Pythagorean triplet is a set of three natural numbers, a < b < c,
  4. # for which, a^2 + b^2 = c^2 For example,
  5. # 3^2 + 4^2 = 9 + 16 = 25 = 5^2. There exists exactly one Pythagorean
  6. # triplet for which a + b + c = 1000. Find the product a * b * c.
  7.  
  8. for c in range(997, 2, -1):
  9.     for b in range((999 - c) // 2 + 1, 1, -1):
  10.         a = 1000 - (b + c)
  11.         if a ** 2 + b ** 2 == c ** 2:
  12.             print(a * b * c)
  13.             exit(0)
  14.  
  15. # 31875000
  16. # 6 function calls in 0.168 seconds
Add Comment
Please, Sign In to add comment