Huawei pen questions 1

def fun():
   p = 120#int(input())
   cnt=0
   for i in range(3,int(p/3)):
       tmp = (p*(p-2*i))%(p-i)
       if tmp==0:
           j=(p*(p-2*i)/(p-i))/2
           k=p-i-j
           if k>j:
               cnt+=1
   print(cnt)
           
fun()

The number given perimeter p, find all satisfy a + b + c = p and right triangle: Huawei written questions

Thinking: given a first side, in 3 ~ p / 3, and according to c = pac, a ^ 2 + b ^ 2 = c ^ 2, simplifying obtain b = (p * (p-2 * a)) / (pa) / 2; when b is a positive integer, satisfying,

Guess you like

Origin www.cnblogs.com/joelwang/p/11426533.html