💥💥 Beats 100% on runtime and memory [EXPLAINED]
Intuitionfind pairs of numbers in nums whose GCD is divisible by query values. The approach is to count frequency and then calculate pairs using divisors and in
# Intuition
find pairs of numbers in nums whose GCD is divisible by query values. The approach is to count frequency and then calculate pairs using divisors and inclusion-exclusion.

# Approach
Count frequencies, calculate divisor pairs using multiples, adjust with inclusion-exclusion, and use prefix sums to answer each query efficiently.

# Complexity
- Time complexity:
O(n * log(max_value)), where n is the length of nums and max_value is the largest number in nums.

- Space complexity:
O(max_value), for storing frequencies and results.

# Code
```kotlin []
class Solution {
    fun gcdValues(nums: IntArray, queries: LongArray): IntArray {
        val maxi = nums.maxOrNull() ?: 0
        val f = LongArray(maxi + 1)
        val ans = LongArray(maxi + 1)
        
        for (num in nums) f[num]++

        for (i in 1..maxi) {
            var ct = 0L
            for (j in i..maxi step i) {
                ct += f[j]
            }
            ans[i] = (ct * (ct - 1) / 2)
        }

        for (i in maxi downTo 1) {
            for (j in i + i..maxi step i) {
                ans[i] -= ans[j]
            }
        }

        val prefix = LongArray(maxi + 1) { ans[it] }
        for (i in 1..maxi) {
            prefix[i] += prefix[i - 1]
        }

        val res = mutableListOf<Int>()
        for (q in queries) {
            var l = 1L
            var r = maxi.toLong()
            var temp = maxi.toLong()

            while (l <= r) {
                val mid = l + (r - l) / 2
                if (prefix[mid.toInt()] >= q + 1) {
                    temp = mid
                    r = mid - 1
                } else {
                    l = mid + 1
                }
            }
            res.add(temp.toInt())
        }

        return res.toIntArray()
    }
}

```
['Array', 'Hash Table', 'Math', 'Binary Search', 'Dynamic Programming', 'Matrix', 'Combinatorics', 'Counting', 'Kotlin']