Approach hintTry it first, then revealHide
Because lcm distributes over gcd, the gcd over all pairs starting at i equals lcm(a[i], gcd(a[i+1..n])). Take the gcd of these values using suffix gcds, in O(n log C).
Because lcm distributes over gcd, the gcd over all pairs starting at i equals lcm(a[i], gcd(a[i+1..n])). Take the gcd of these values using suffix gcds, in O(n log C).