FastPrepSum of Divisors of the Array GCD

Sum of Divisors of the Array GCD

Zscaler logoZscaler● EasyINTERNPHONE SCREEN
Learn

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[]) → long

Examples

Example 1

values = [6,12,18]return = 12

The array GCD is 6. Its positive divisors are 1, 2, 3, 6, whose sum is 12.

Example 2

values = [7,14]return = 8

The GCD is 7, so the divisor sum is 1 + 7 = 8.

Example 3

values = [8,16,32]return = 15

The GCD is 8. Its divisors 1, 2, 4, 8 sum to 15.

Constraints

  • 1 <= values.length <= 200000
  • 1 <= values[i] <= 10^9
  • The answer fits in a signed 64-bit integer.

More Zscaler problems

See Zscaler hiring insights
public long sumDivisorsOfArrayGcd(int[] values) {
  // write your code here
}
values[6,12,18]
expected12
Checking account…