A square triple (a,b,c)
is a triple where a
, b
, and c
are integers and a2 + b2 = c2
.
Given an integer n
, return the number of square triples such that 1 <= a, b, c <= n
.
Input: n = 5 Output: 2 Explanation: The square triples are (3,4,5) and (4,3,5).
Input: n = 10 Output: 4 Explanation: The square triples are (3,4,5), (4,3,5), (6,8,10), and (8,6,10).
1 <= n <= 250
class Solution:
def countTriples(self, n: int) -> int:
ret = 0
for a in range(1, n):
for b in range(1, n):
c = int((a * a + b * b) ** 0.5)
if c <= n and c * c == a * a + b * b:
ret += 1
return ret