We are to compute the gcd of all pairwise lcms of a given sequence a of length n (up to 100k), with a_i up to 200k.
We need gcd_{i<j} lcm(a_i, a_j).
Observation: lcm(a_i, a_j) = a_i * a_j / gcd(a_i, a_j). So the gcd of these lcms is something like gcd over i<j of (a_i * a_j / gcd(a_i, a_j)).
But direct computation O(n^2) is too slow.
We need to find a clever way.
Let's denote the answer as G = gcd_{i<j} lcm(a_i, a_j).
We can think in terms of prime factorization.
Let the set of numbers be A = {a_1, ..., a_n}.
For each prime p, consider its exponents in each a_i. Let v_i = v_p(a_i). Then v_p(lcm(a_i, a_j)) = max(v_i, v_j). And the gcd over all these lcms will take the minimum over all pairs of max(v_i, v_j). Actually, for the gcd of a set of numbers, the exponent for p in the gcd is the minimum exponent of p among all numbers in the set. So:
v_p(G) = min_{i<j} v_p(lcm(a_i, a_j)) = min_{i<j} max(v_i, v_j).
So we need to compute, for each prime p, the minimum over all pairs of the maximum of the two exponents.
Given the multiset of exponents v_i (maybe many zeros). Let’s denote the multiset of v_i for prime p. We need m(p) = min_{i<j} max(v_i, v_j). Equivalent to: among all unordered pairs (i,j) with i!=j, take the max of their two exponents, and then take the minimum of those max values.
We can think: For a given threshold t, is there a pair such that max(v_i, v_j) <= t? Actually we want the minimum possible max. That is like: we need to find the smallest integer m such that there exists a pair (i,j) with both v_i <= m? Wait no: max(v_i, v_j) <= m means both v_i <= m and v_j <= m. So the condition that max(v_i, v_j) <= m is that both are <= m. So if there are at least two numbers with exponent <= m, then the max for that pair is <= m. However, we are looking for the minimum over pairs of max; that minimum value is the smallest m such that there exist at least two numbers with exponent <= m? Actually careful:
Let S = {v_i}. Consider all pairs. For each pair, we compute max(v_i, v_j). Among those values, we take the minimum. Denote that as m*.
Now, what is m*? Intuitively, if we sort the v_i's: v_{(1)} <= v_{(2)} <= ... <= v_{(n)}. Then the smallest max among pairs is obtained by taking the two smallest elements: max(v_{(1)}, v_{(2)}) = v_{(2)}. Because if we take any other pair, the max will be at least v_{(2)} (since the second smallest is the smallest possible for the larger element). Indeed, consider any pair: the larger of the two is at least v_{(2)} because the two smallest values are v_{(1)} and v_{(2)}; any other pair's larger element is at least v_{(2)} (could be v_{(2)} if one is v_{(1)} and the other is v_{(2)} or greater? Actually if we take pair (v_{(1)}, v_{(3)}), max = v_{(3)} which is >= v_{(2)}). So the minimum max is indeed the second smallest value in the multiset of exponents. So v_p(G) = second smallest exponent among the v_i's for prime p. But wait, is that always true? Let's test: Suppose exponents: [5,5,0,0]. Sorted: 0,0,5,5. The two smallest are