You are given a tree with nums of length edges of length edges[j] = [u_j, v_j] indicates an undirected edge between nodes u_j and v_j. Each node i has a value nums[i].
Two integers are coprime if their greatest common divisor is
For each node i from nums[i].
Return an array ans of length ans[i] is the closest coprime ancestor of node i, or
Note: A node
uis an ancestor of nodevifulies on the path from the root nodeto node v, anduis not equal tov.
Constraints:
nums.length
nums[i]
edges.length
edges[j].length
u_j, v_j
u_j v_j
You are given a tree with nums of length edges of length edges[j] = [u_j, v_j] indicates an undirected edge between nodes u_j and v_j. Each node i has a value nums[i].
Two integers are coprime if their greatest common divisor is
For each node i from nums[i].
Return an array ans of length ans[i] is the closest coprime ancestor of node i, or
Note: A node
uis an ancestor of nodevifulies on the path from the root nodeto node v, anduis not equal tov.
Constraints:
nums.length
nums[i]
edges.length
edges[j].length
u_j, v_j
u_j v_j