Problème
Afficher la traductionFind 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.
Contraintes
3 ≤ perimeter ≤ 100,000. Products fit signed 64-bit integers.
Exemples
Entrée :
perimeter = 30
Sortie attendue :
expected = 780
Entrée :
long long perimeter = 30;
Sortie attendue :
long long expected = 780;
Entrée :
long perimeter = 30;
Sortie attendue :
long expected = 780;
Explication
The triangle is (5, 12, 13): 25 + 144 = 169 and 5 + 12 + 13 = 30. Its product is 780.
Entrée :
perimeter = 11
Sortie attendue :
expected = -1
Entrée :
long long perimeter = 11;
Sortie attendue :
long long expected = -1;
Entrée :
long perimeter = 11;
Sortie attendue :
long expected = -1;
Explication
No increasing positive integer right-triangle sides sum to 11.
Références
Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.