Trung bình 0 đã giải Tỷ lệ chấp nhận 0%

Right-Triangle Product

Find the largest side product of an integer right triangle with a given perimeter.

Find 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ụ

Ví dụ 1
Đầ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.

Ví dụ 2
Đầ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.

Học hỏi từ người khác

Giải pháp cộng đồng

Chưa có giải pháp nào được chia sẻ. Hãy giải thử thách này để đăng giải pháp đầu tiên.