#3715

Sum of Perfect Square Ancestors

master · 1640 · lc hard +32 · 42.6% accepted · 67 likes · top 24%

Description

Given an n-node tree rooted at node 0 described by edges and node-value array nums, for each node i (from 1 to n - 1) count the ancestors a such that nums[i] * nums[a] is a perfect square; return the sum of all such counts.

Code

1
2
3