Sum of Divisors of the Array GCD
Problem statement
Given a nonempty array of positive integers values, compute the greatest common divisor of all values.
Return the sum of every positive divisor of that GCD.
Function
sumDivisorsOfArrayGcd(values: int[]) → longExamples
Example 1
values = [6,12,18]return = 12The array GCD is 6. Its positive divisors are 1, 2, 3, 6, whose sum is 12.
Example 2
values = [7,14]return = 8The GCD is 7, so the divisor sum is 1 + 7 = 8.
Example 3
values = [8,16,32]return = 15The GCD is 8. Its divisors 1, 2, 4, 8 sum to 15.
Constraints
1 <= values.length <= 2000001 <= values[i] <= 10^9- The answer fits in a signed 64-bit integer.