Special Pythagorean Triplet
A Pythagorean triplet is a tuple of positive integers (a, b, c) with a < b < c and a^2 + b^2 = c^2. Find the unique such triplet satisfying a + b + c = 1000, and compute the product abc.
Problem Statement
This archive keeps the full statement, math, and original media on the page.
A Pythagorean triplet is a set of three natural numbers, $a < b < c$, for which, $$a^2 + b^2 = c^2.$$ For example, $3^2 + 4^2 = 9 + 16 = 25 = 5^2$.
There exists exactly one Pythagorean triplet for which $a + b + c = 1000$.
Find the product $abc$.
Problem 9: Special Pythagorean Triplet
Mathematical Development
Parametric Reduction
Theorem 1 (Reduction to a single variable). Suppose positive integers satisfy
for a given . Then
Proof. From the sum constraint, . Substituting into the Pythagorean condition:
Cancelling from both sides:
Solving for :
hence .
Corollary 1. Setting :
Theorem 2 (Integrality condition). With , the value is a positive integer if and only if .
Proof. Perform polynomial long division on the numerator:
Equivalently, write , so
For , we need and , i.e., , i.e., .
Enumeration of Solutions
Theorem 3 (Existence and uniqueness). The unique Pythagorean triplet with and is .
Proof. We require:
- ,
- with .
The prime factorization has positive divisors. Setting , we need and , so . Also by Theorem 2.
The divisors of in the range are:
- : , , . Here , so reorder: .
- : , , . This gives .
Both cases yield the same triplet. No other divisor of lies in .
Verification. . Also . The ordering holds.
Remark. The triplet , where is a primitive Pythagorean triple generated by the classical parametrization with : , , .
Editorial
We iterate over the possible first leg and use the linear relation derived from and to solve for . For each , we compute the candidate numerator and denominator, check whether the division is exact, recover and , and return the product once the ordering holds. This is sufficient because every Pythagorean triple with sum must satisfy the derived formula for .
Pseudocode
Algorithm: Special Pythagorean Triple for a Fixed Perimeter
Require: A target perimeter s.
Ensure: The product abc for the unique Pythagorean triple with a + b + c = s.
1: For each admissible value of a in increasing order do:
2: Compute nu ← s(s - 2a) and delta ← 2(s - a).
3: If delta divides nu, set b ← nu / delta and c ← s - a - b.
4: If a < b < c and a^2 + b^2 = c^2, return a · b · c.
5: Return failure if no such triple exists.
Complexity Analysis
Theorem 4. The algorithm finds the triplet in time and space, where .
Proof. The outer loop iterates from 1 to at most (since and imply ). Each iteration performs arithmetic: one division and a divisibility check. No auxiliary data structures are needed.
Remark. An algorithm is possible by directly iterating over divisors of , but the linear approach suffices for .
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
const int s = 1000;
for (int a = 1; a < s / 3; a++) {
int num = s * s / 2 - s * a;
int den = s - a;
if (num % den == 0) {
int b = num / den;
int c = s - a - b;
if (a < b && b < c) {
cout << (long long)a * b * c << endl;
return 0;
}
}
}
return 0;
}
s = 1000
for a in range(1, s // 3):
num = s * s // 2 - s * a
den = s - a
if num % den == 0:
b = num // den
c = s - a - b
if a < b < c:
print(a * b * c)
break