Project Euler #9: Special Pythagorean triplet

  • + 0 comments

    Solution in python :

    t = int(input().strip())
    for _ in range(t):
        N = int(input().strip())
        max_product = -1
    
        for a in range(1, N // 3):
            b = (N * (N - 2 * a)) // (2 * (N - a))
            c = N - a - b
            if a < b < c and a * a + b * b == c * c:
                max_product = max(max_product, a * b * c)
        
        print(max_product)