All problems
1173EasyMathEnumeration

Triples of Squares That Add Up

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1925Count Square Sum Triples

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

Return how many ordered triples (a, b, c) of whole numbers between 1 and n satisfy a * a + b * b == c * c.

Triples in a different order count separately, so (3, 4, 5) and (4, 3, 5) are two of them.

Examples

Example 1

Input
n = 13
Output
6

Three pairs of legs work within thirteen, each counted twice for its two orders: 3 with 4, 6 with 8, and 5 with 12.

Example 2

Input
n = 12
Output
4

Two pairs work within twelve, 3 with 4 and 6 with 8, each counted twice.

Example 3

Input
n = 4
Output
0

Nothing within four works at all.

Constraints

  • 1 <= n <= 250

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def count_triples(n: int) -> int:
Java
public int countTriples(int n)
September 7
Apply