모든 챌린지
보통 0명 해결 정답률 0%

Find Right-Triangle Triples

List all integer right triangles with a specified perimeter.

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.

예시

예시 1
입력:
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.

예시 2
입력:
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에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.