Project Euler

Problem 9: Special Pythagorean triplet

There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. Run this solution at repl.io here.

      
        from math import sqrt

        s = 1000.0 #sqrt returns floats

        for a in range(1,int(s)):
          for b in range(1,int(s)):
            c = sqrt(a*a + b*b)
            if a + b + c == s:
              print("(a,b,c) = (" + str(a) + ", " + str(b) + ", " + str(int(c)) + ")")
              print(a*b*int(c))
      
    

back to code menu