Problem
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.
Algorithm
Count the number of Pythagorean triples by enumerating them according to the definition.
Code
python3
class Solution:
def countTriples(self, n: int) -> int:
cnts = 0
for a in range(2, n):
for b in range(2, n):
c_2 = a * a + b *b
c = int(sqrt(c_2))
if c <= n and c * c == c_2:
cnts += 1
return cnts