문제
번역본 보기Find every triple of positive integers a < b < c for which a² + b² = c² and a + b + c = perimeter. Return each triple as [a, b, c], ordered by increasing a and then b. Do not include permutations of the same sides.
Implement pythagorean_triplets(perimeter).
Input
perimeter: The required sum of all three sides.
Output
Return a list of triples in the specified order.
제약 조건
3 ≤ perimeter ≤ 100,000. Return an empty list if no triangle qualifies.
예시
입력:
perimeter = 30
예상 출력:
expected = [
[5, 12, 13]
]
입력:
long long perimeter = 30;
예상 출력:
std::vector<std::vector<long long>> expected = {
{5, 12, 13}
};
입력:
long perimeter = 30;
예상 출력:
long[][] expected = new long[][] {
new long[] {5, 12, 13}
};
설명
5 + 12 + 13 = 30 and 5² + 12² = 13². This is the only qualifying triple.
입력:
perimeter = 11
예상 출력:
expected = []
입력:
long long perimeter = 11;
예상 출력:
std::vector<std::vector<long long>> expected = {};
입력:
long perimeter = 11;
예상 출력:
long[][] expected = new long[][] {};
설명
No increasing positive integer right-triangle triple sums to 11.
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.