title: Can I make this function more efficient (Project Euler Number 9)?
body: <p>I just finished Project Euler problem 9 (warning <strong>spoilers</strong>):</p>
  
  <pre><code>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 = 1000.
  Find the product abc.
  </code></pre>
  
  <p>Here's my solution:</p>
  
  <pre><code>public static int specPyth(int num)
  {
      for (int a = 1; a &lt; num; a++)
          for (int b = 2; b &lt; a; b++)
              {
                  if (a*a +b*b == (num-a-b)*(num-a-b))
                      return a*b*(num-a-b); //ans = 31875000 
              }
  
      return -1;
  }
  </code></pre>
  
  <p>I can't help but think that there's a solution that involves only one loop.  Anyone have ideas? I'd prefer answers using only one loop, but anything that's more efficient than what I currently have would be nice.</p>