# solving the triangles problem - version 4
# defining the content of the innermost loop as a single atomic operation
# (which takes a constant time),
# and p as the input size,
# the complexity is O(p**2)
def nirt_v4(p):
cnt = 0
for a in range(1,p//3+1):
for b in range(a,(p-a)//2+1):
c = p-a-b
if a*a+b*b == c*c:
cnt += 1
return cnt