Java ( with hindi comments to better understand )
Intuition\nHindi Comments m sb explain krdia h..  do upote\n\n# Approach \nStore divisors for each number.\nCalculate the number of pairs for each GCD from the 
# Intuition\nHindi Comments m sb explain krdia h..  do upote\n\n# Approach \nStore divisors for each number.\nCalculate the number of pairs for each GCD from the maximum down to 1.\nBuild a prefix sum of pairs to quickly answer each query using binary search.\n\n\n# Complexity\n- Time complexity:\nThe overall time complexity of this algorithm is $$O(n * sqrt(E))$$, where n is the size of the array and E is the maximum value in the array.\n\n- Space complexity:\n$$O(n)$$ to store divisors of every element\n\n# Code\n```java []\n/*\n\nhrek pair nikalne s TLE aa jaega to hum nums[i] ki range dekhte hain usey kuj hoskta h kya \n\nek kaam krte hain hrek number ka divisor store krlete hain ek array me\n\narr[i] = j means   i divisor j baar aaya h poore array k elements k divisor me \n\n\n*/\nclass Solution {\n    public int[] gcdValues(int[] nums, long[] queries) {\n        \n       long divisorOfElements[] = new long[50001];\n        int n = nums.length;\n       // store every divisor in divisor array\n\n       for(var e : nums)\n       {\n            for(int i = 1;(i*i)<=e;i++)\n            {\n                if(e%i == 0)\n                {\n                    int x = i ;\n                    int y = e/i ;\n\n\n                    // agr number perfect square haito ek baar judega \n                    if(x == y)\n                    {\n                        divisorOfElements[x]++ ;\n                    }else\n                    {\n                        divisorOfElements[x]++ ;\n                        divisorOfElements[y]++ ;\n                    }\n                }\n            }\n       }\n\n       // yaha tkk hmne hrek no ka hrek divisor store krlia h \n\n       // ab suppose ki arr[i] = j hai mtlb ki total j elements aise the jinme i ek divisor tha \n       // mtlb ki j*(j-1)/2 pairs ho gaye inn elements k to ek kaam krte hain ab isi array k values \n       // pair m represent krdege isi formula s ie arr[i] = j means j pair total bnege jisme i dovisor tha \n\n       for(int i = 1;i<= 50000 ;i++)\n       {\n            long value = divisorOfElements[i];\n\n            divisorOfElements[i] = value * (value-1) / 2 ;\n       }\n\n       // ab hme ye pta lgg gya h ki hrek divisor kitne pair m contri krege \n\n       // ab last s travel krte hain and suppose i = 4 p hain to isske maanlo 8 pairs m contribute kia \n       // to 4 k divisor me khud  1 , 2 aata h mtlb 4 ka jitne pairs hain wo 2 ka pairs m b count ho rhe honge \n       // to hme 4 k jitne pairs hain uske 4 k divisors me  s htana pdega to last s travel krk ye krlete hain pehle \n\n       for(int i = 50000 ; i >= 1;i--)\n       {\n            if(divisorOfElements[i] > 0)\n            {\n                // jitne bhi divisor hain i k unn sbme s i k pair htao\n\n                for(int j = 1 ; (j*j) <= i ;j++)\n                {\n                    if(i % j == 0)\n                    {\n                        int x = j ;\n                        int y = i/j ;\n\n                        if(x == y && y != i)\n                        {\n                            divisorOfElements[x] -= divisorOfElements[i];\n                        }else\n                        {\n                        \n                            if(x != i)   // qki equal hue toh hum main loop m handle kr lege \n                            divisorOfElements[x] -= divisorOfElements[i];\n\n                            if(y != i)\n                            divisorOfElements[y] -= divisorOfElements[i];\n                        }\n                    }\n                }\n            }\n       }\n\n       // bss ab hmare paas aagya h knsa divisor kitne pair ka GCD hai bss ab queries ko handle krna h \n\n       // sbhi pairs ka sum krdete hain and prefix sum bnaa lete hai . WHY ? \n       // qki suppose query hai 5 mtlb hme 6th value btaani h to binary search lgaakr 6th value kis index p hai wo\n       // aajaega to wahi index (ir divisor hmara ans hoga )\n\n       for(int i=1;i<= 50000;i++)\n       {\n            divisorOfElements[i] = divisorOfElements[i] + divisorOfElements[i-1];\n       }\n\n       // ab hrek query k liy binary search s position dhund lo \n       // suppose array [2,3,5] and hme query 4 dia h mtlb ki hm 5 ka index return krege wahi ttkk 5 elemen hue honge \n\n        int[] ans = new int[queries.length];\n        int idx = 0 ;\n       for(var q : queries)\n       {\n            ans[idx++] = (int)lowerBound(divisorOfElements , q+1) ;\n       }\n\n       return ans ;\n\n    }\n\n    private long lowerBound(long[] arr, long ele) {\n    int i = 0, j = arr.length;\n\n    while (i < j) { // Changed to i < j for binary search logic\n        int mid = i + (j - i) / 2;\n\n        if (arr[mid] < ele) {\n            i = mid + 1;\n        } else {\n            j = mid;\n        }\n    }\n\n    return i; // Returning the correct index for lower bound\n}\n\n} \n```
['Java']