Your last submission beat 100% of other submissions' runtime.
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```java []\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\n\nclass Solution {\n    public int[] gcdValues(int[] nums, long[] queries) {\n        Arrays.sort(nums);\n        int[] cntd = new int[50001];\n        long[] cntgcd = new long[50001];\n        int n = nums.length;\n        for (int i = n - 1; i >= 0; i--) {\n            ArrayList<Integer> divisor = new ArrayList<>();\n            for (int d = (int) Math.sqrt(nums[i]); d >= 1; d--) {\n                if (nums[i] % d == 0) {\n                    divisor.add(d);\n                    if (d * d < nums[i])\n                        divisor.add(nums[i] / d);\n                }\n            }\n            Collections.sort(divisor);\n            int[] addgcd = new int[50001];\n            for (int j = divisor.size() - 1; j >= 0; j--) {\n                int d = divisor.get(j);\n                addgcd[d] += cntd[d];\n                for (int k = j + 1; k < divisor.size(); k++) {\n                    int dd = divisor.get(k);\n                    if (dd % d == 0)\n                        addgcd[d] -= addgcd[dd];\n                }\n            }\n            for (int d : divisor) {\n                cntd[d]++;\n                cntgcd[d] += addgcd[d];\n            }\n        }\n\n        long[] sum = new long[50001];\n        for (int i = 1; i <= 50000; i++)\n            sum[i] = sum[i - 1] + cntgcd[i];\n        int[] rst = new int[queries.length];\n        for (int i = 0; i < queries.length; i++) {\n            int left = 0, right = 50000;\n            while (left + 1 < right) {\n                int mid = (left + right) >> 1;\n                if (sum[mid] >= queries[i] + 1)\n                    right = mid;\n                else\n                    left = mid;\n            }\n            rst[i] = right;\n        }\n        return rst;\n    }\n}\n\n```
['Java']