Java with concise inline comments
Basically just what the top solutions did, but with inline comments\n\n# Code\njava []\nclass Solution {\n    public int[] gcdValues(int[] nums, long[] queries)
Basically just what the top solutions did, but with inline comments\n\n# Code\n```java []\nclass Solution {\n    public int[] gcdValues(int[] nums, long[] queries) {\n        // count divisors for each num\n        int max = Arrays.stream(nums).max().orElse(0);\n        int[] divCount = new int[max + 1];\n        for (int num : nums) {\n            for (int i = 1; i * i <= num; i++) {\n                if (num % i == 0) {\n                    divCount[i]++;\n                    if (num / i != i) {\n                        divCount[num / i]++;\n                    }\n                }\n            }\n        }\n\n        long[] gcdCount = new long[max + 1];  // gcdCount[i] = (# of pairs with i as their GCD)\n        for (int i = max; i >= 1; i--) {\n            // init as # of ways to choose 2 num from all nums w/ i as its divisor\n            //  nCr = n!/((n-r)!r!)\n            gcdCount[i] = (long)divCount[i] * ((long)divCount[i] - 1) / 2; \n\n            // rid out repeated countings (counted in i\'s multiples, where i is not the real GCD)\n            for (int mult = i * 2; mult <= max; mult += i) {\n                gcdCount[i] -= gcdCount[mult];\n            }\n        }\n\n\n        // Then the problem becomes [528. random pick with weight]\n        \n        long[] prefixSum = new long[max + 1];  // prefixSum[i] = (# of GCD <= i)\n        for (int i = 1; i < gcdCount.length; i++) {\n            prefixSum[i] = prefixSum[i-1] + gcdCount[i];\n        }\n\n        int[] res = new int[queries.length];\n        for (int i = 0; i < queries.length; i++) {\n            long q = queries[i];\n            int l = 1, r = max;\n\n            // find the smallest m where prefixSum[m] >= q + 1\n            while (l + 1 < r) {\n                int m = l + (r - l) / 2;\n                if (prefixSum[m] >= q + 1) {\n                    r = m;\n                } else {\n                    l = m;\n                }\n            }\n\n            if (prefixSum[l] >= q + 1) res[i] = l;\n            else res[i] = r;            \n        } \n\n        return res;\n    }\n}\n```
['Java']