#Problem: #How many right triangles with integer edges have given perimeter p? #note: in all solutions the condition b=1 cover it import time #cubic complexity in p - O(p^3) def number_of_integer_right_triangles_v1(p): cnt = 0 for a in range(1,p): for b in range(1,p): for c in range(1,p): if a <= b < c and a+b+c == p and a*a+b*b == c*c: cnt += 1 return cnt #quadratic complexity in p - O(p^2) def number_of_integer_right_triangles_v2(p): cnt = 0 for a in range(1,p): for b in range(1,p): c = p-a-b if a <= b < c and a*a+b*b == c*c: cnt += 1 return cnt #quadratic complexity in p - O(p^2) def number_of_integer_right_triangles_v3(p): cnt = 0 for a in range(1,p): for b in range(a+1,p): c = p-a-b if b < c and a*a+b*b == c*c: cnt += 1 return cnt #quadratic complexity in p - O(p^2) def number_of_integer_right_triangles_v4(p): cnt = 0 for a in range(1,p//3+1): #a = p-b-c <= p-2a --> 3a

2b