Tất cả thử thách
Trung bình 0 đã giải Tỷ lệ chấp nhận 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.

Ràng buộc

3 ≤ perimeter ≤ 100,000. Return an empty list if no triangle qualifies.

Ví dụ

Ví dụ 1
Đầu vào:
perimeter = 30

Kết quả mong đợi:
expected = [
    [5, 12, 13]
]
Đầu vào:
long long perimeter = 30;

Kết quả mong đợi:
std::vector<std::vector<long long>> expected = {
    {5, 12, 13}
};
Đầu vào:
long perimeter = 30;

Kết quả mong đợi:
long[][] expected = new long[][] {
    new long[] {5, 12, 13}
};

Giải thích

5 + 12 + 13 = 30 and 5² + 12² = 13². This is the only qualifying triple.

Ví dụ 2
Đầu vào:
perimeter = 11

Kết quả mong đợi:
expected = []
Đầu vào:
long long perimeter = 11;

Kết quả mong đợi:
std::vector<std::vector<long long>> expected = {};
Đầu vào:
long perimeter = 11;

Kết quả mong đợi:
long[][] expected = new long[][] {};

Giải thích

No increasing positive integer right-triangle triple sums 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.