As reported: Tower Research Capital online assessment (2026): a tree of
Nservers with positive valuesA_i;MEX-P(S)is the smallest primepsuch that some element ofSis not divisible byp;f(u, v)is theMEX-Pof the values on the path fromutov; outputB_u = Σ_v f(u, v)for every serveru(v = uincluded).
Tower Research's backbone is a tree of n servers; server i has a positive integer value A_i.
For a non-empty set S of positive integers, MEX-P(S) is the smallest prime p such that some element of S is not divisible by p. For example, MEX-P({4, 2, 8, 16}) = 3 and MEX-P({30, 210}) = 7.
For servers u and v, let f(u, v) be MEX-P of the values of all servers on the unique path from u to v (both ends included; for u = v the path is just u). For every server u, compute
B_u = f(u, 1) + f(u, 2) + … + f(u, n)
Example 1
n = 4, A = [6,30,2,1], edges = [[1,2],[1,3],[3,4]]
Output: [15,17,11,8]
For u = 1: f(1,1) = MEX-P({6}) = 5, f(1,2) = MEX-P({6,30}) = 5, f(1,3) = MEX-P({6,2}) = 3, f(1,4) = MEX-P({6,2,1}) = 2 → 15.
Example 2
n = 3, A = [210,30,7], edges = [[1,2],[2,3]]
Output: [20,16,6]
Constraints: 1 ≤ n ≤ 2 · 10^5; 1 ≤ A_i ≤ 10^9; edges has n − 1 pairs [u, v] (1-based) forming a tree.
Code runner format: one JSON value per line: n, A, edges. Implement mexpSums(n, A, edges) and return [B_1, …, B_n].