Đề bài
Xem bản dịchFind positive integers a < b < c with a² + b² = c² and a + b + c = perimeter. Return the largest product a × b × c among qualifying triangles, or −1 if there are none. This generalizes the fixed-perimeter source task and explicitly handles multiple answers.
Implement pythagorean_product(perimeter).
Input
perimeter: The required sum of the three sides.
Output
Return the largest product, or −1 when no triangle qualifies.
Ràng buộc
3 ≤ perimeter ≤ 100,000. Products fit signed 64-bit integers.
Ví dụ
Đầu vào:
perimeter = 30
Kết quả mong đợi:
expected = 780
Đầu vào:
long long perimeter = 30;
Kết quả mong đợi:
long long expected = 780;
Đầu vào:
long perimeter = 30;
Kết quả mong đợi:
long expected = 780;
Giải thích
The triangle is (5, 12, 13): 25 + 144 = 169 and 5 + 12 + 13 = 30. Its product is 780.
Đầu vào:
perimeter = 11
Kết quả mong đợi:
expected = -1
Đầu vào:
long long perimeter = 11;
Kết quả mong đợi:
long long expected = -1;
Đầu vào:
long perimeter = 11;
Kết quả mong đợi:
long expected = -1;
Giải thích
No increasing positive integer right-triangle sides sum to 11.
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.