Finding Pythagorean Triple that sums to 1000 I am doing this Project Euler Question #9:


  A Pythagorean triplet is a set of three natural numbers, \$a &lt; b &lt; 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 =
&gt; 1000\$.
  Find the product \$abc\$.


I have implemented the code but I feel like it runs slow and doesn't perform well enough:

def check_pathagorean(a, b, c):
    return (a**2) + (b**2) == (c**2)

SUM = 1000

for i in range(1, SUM):
    for j in range(i+1, SUM):
        c = SUM - (i + j)
        if(check_pathagorean(i, j, c)):
            if i + j + c == SUM:
                print i * j * c
                break


What could I do to make this run faster and better?
Any pythagorean triple is in form of


  $$ k(u^2 - v^2), 2kuv, k(u^2 + v^2) $$


where u, v, and k are positive integers with u > v, u − v odd, and with u and v  coprime. The sum is therefore


  $$ ku(u + 2v) $$


(the restrictions still apply).

Now your job is factor 1000 into 3 terms (not so many ways to do so, 1000 = 5*5*5*2*2*2) and determine if those terms can be represented with u and v being coprime with an odd difference.