第五题 找完全平方数 从子节点往前找即可ac。 import math def is_pownum(num): if math.sqrt(num)%1==0: return True else: return False n = int(input()) a = [int(x) for x in input().split()] father = [int(x) for x in input().split()] count=0 for i in range(n-1,-1,-1): j = i while j>0: j = father[j - 1] - 1 if is_pownum(a[i]*a[j]): count+=1 print(count)

相关推荐

牛客网
牛客企业服务