Approach hintTry it first, then revealHide
For a fixed right end, the gcd of subarrays takes only O(log C) distinct values as the left end moves. Carry a map of these values with their counts from one right end to the next and accumulate totals per gcd.