✔️✔️100% Faster JavaScript Solution || Optimized Approach ✌️✌️
Intuition\n Describe your first thoughts on how to solve this problem. \nFor each number num in nums1 we just need to find how many factor of num/k is present i
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor each number num in nums1 we just need to find how many factor of num/k is present in nums2 and sum of all these value will be our answer.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. First I will store frequency of each number of nums2 in map.\n2. Result = 0 \n2. Iterate over all element of nums1 and \n   - If num % k == 0\n   - find count of all divisors of num/k in nums1 and will sum all of these values.\n   - Result += mp.get(divisor);\n3. Result will be the solution\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n1. $$O(m)$$ to store freq of each num of nums2\n2. $$O(n*sqrt(max(nums1)))$$ to find count of all such pairs \n- Space complexity:\n1. $$O(m)$$ to store freq of each num of nums2\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @param {number} k\n * @return {number}\n */\nvar numberOfPairs = function(nums1, nums2, k) {\n    let ans = 0;\n    let n = nums1.length , m = nums2.length;\n    const mp = new Map();\n    for(var num of nums2)\n    {\n        mp.set(num,mp.has(num) ? mp.get(num) + 1 : 1);\n    }\n    for(var v of nums1)\n    {\n        if(v%k ==0)\n        {\n           const val = v/k;\n           for(let i = 1 ; i <= Math.sqrt(val) ; i++)\n           {\n               if(val % i == 0)\n               {\n                  ans += mp.has(i) ? mp.get(i) : 0;\n                  if(val / i != i)\n                  {\n                     ans += mp.has(val / i) ? mp.get(val / i) : 0;  \n                  }\n               }\n           }\n        }\n    }\n    return ans;\n};\n```
['JavaScript']