ปานกลาง 0 ข้อที่แก้แล้ว อัตราผ่าน 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.

เงื่อนไข

3 ≤ perimeter ≤ 100,000. Products fit signed 64-bit integers.

ตัวอย่าง

ตัวอย่างที่ 1
อินพุต:
perimeter = 30

ผลลัพธ์ที่คาดหวัง:
expected = 780
อินพุต:
long long perimeter = 30;

ผลลัพธ์ที่คาดหวัง:
long long expected = 780;
อินพุต:
long perimeter = 30;

ผลลัพธ์ที่คาดหวัง:
long expected = 780;

คำอธิบาย

The triangle is (5, 12, 13): 25 + 144 = 169 and 5 + 12 + 13 = 30. Its product is 780.

ตัวอย่างที่ 2
อินพุต:
perimeter = 11

ผลลัพธ์ที่คาดหวัง:
expected = -1
อินพุต:
long long perimeter = 11;

ผลลัพธ์ที่คาดหวัง:
long long expected = -1;
อินพุต:
long perimeter = 11;

ผลลัพธ์ที่คาดหวัง:
long expected = -1;

คำอธิบาย

No increasing positive integer right-triangle sides sum to 11.

แหล่งอ้างอิง

โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก