Все задачи
Средне Решено: 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. Следуйте условию и ограничениям выше.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.