MathsReadCompetitive mathematics
Algorithmic puzzle · integer answereasy25 min

Primitive hypotenuse pairs

Lattice Geometry

Count pairs of integers (a,b) with 1<=a<b<=500, a+b<=600, gcd(a,b)=1, and a^2+b^2 a perfect square.

Solve using mathematics, algorithms, or your own code offline. Submit only the final integer here—no program, expression, graph, or written proof.

Check your answer without signing in. Sign in to save your progress.

Accepted format: a whole number such as 42 or 123456789. No commas, formulas, or source code.

How to approach this problem

Enumerate ordered leg pairs with a<b and the perimeter restriction on their sum. Test coprimality and whether the squared hypotenuse is a perfect square using an integer square root.

Worked example with different values

(3,4) gives hypotenuse 5 and gcd 1. (6,8) also forms a right triangle but is not primitive.

Apply the same reasoning to the challenge. This example is a separate practice problem.

Learn the technique: Number theory: divisors, gcd and modular arithmetic

Report a question or explanation issue

Back to problems →