# solving the triangles problem - version 5
# 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)
def nirt_v5(p):
cnt = 0
for a in range(1,p//3+1):
b = (p**2-2*p*a)/(2*(p-a))
if int(b) == b and a < b:
cnt += 1
return cnt