समस्या
अनुवाद दिखाएँ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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।