Project Euler problem 9 says:
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 \$abc\$.
My code finds the correct solution to the problem. The problem is it takes 47.6 seconds to get it, so I'd like to optimize it, but don't know exactly how to do so further. I've already reduced the range of the for loops.
import time s=time.time() a=0 b=0 c=0 for i in range(1,499): #max value for any side of the triangle must be less than the semiperimeter for j in range(i,499): for k in range(j,499): if(i+j+k==1000 and i**2+j**2==k**2): a=i b=j c=k break #the solution is unique, so when it finds a solution, it doesnt need to go through any other loops. print(a*b*c,time.time()-s)