Python3. GCD
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def gcdValues(self, nums: List[int], queries: List[int]) -> List[int]:\n\n        max_num = max(nums)\n        # cn = Counter(nums)\n        # hs = defaultdict(int)\n\n        # 1.\n        # for i in range(1, max_num + 1):\n        #     for c in cn:\n        #         if c % i == 0:\n        #             hs[i] += cn[c]\n        \n        # print(hs)\n\n        count = [0] * (max_num + 1)\n        for num in nums:\n            count[num] += 1\n\n        hs = [0] * (max_num + 1)\n        for i in range(1, max_num + 1):\n            for multiple in range(i, max_num + 1, i):\n                hs[i] += count[multiple]\n\n        2. \n        for h in range(len(hs)):\n            hs[h] = (hs[h] * (hs[h] - 1)) // 2\n\n        3\n        mhs = defaultdict(int)\n        for h in range(max_num, 0, -1):\n            total = hs[h]\n            for k in range(2 * h, max_num + 1, h):\n                total -= mhs[k]\n            mhs[h] = total\n\n        # print(mhs)\n\n        4\n        ans = []\n        prefix = []\n        total = 0\n        for h in sorted(mhs):\n            count = mhs[h]\n            if count > 0:\n                total += count\n                ans.append(h)\n                prefix.append(total)\n            \n        # print(ans, prefix)\n\n        ar = []\n        for q in queries:\n            ind = bisect_left(prefix, q + 1)\n            if ind < len(ans):\n                ar.append(ans[ind])\n            else:\n                ar.append(-1)\n        \n        # print(ar)\n        return ar\n\n\n  \n\n\n        \n```
['Python3']