Easy Java Solution | Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nThis is a direct question. The brute force approach itself is the fastest solution.\n\n
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis is a direct question. The brute force approach itself is the fastest solution.\n\nWe just need to pick up every possible pair of numbers and try the conditions mentioned in the question.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUsing two for loops as shown in the code below, every pair of numbers can be picked from the array. The conditions are checked and if they are met, then a count variable is incremented.\n\nThis count variable is then returned as the required result.\n\n# Complexity\n- Time complexity: O(n<sup>2</sup>)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nThis is because we are using two nested for loops to traverse through the array.\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nOnly a single variable is used to keep track of count, thus using constant space, regardless of input size.\n\n# Code\n```\nclass Solution {\n    public int countPairs(int[] nums, int k) {\n        int count = 0;\n        for(int i = 0; i < nums.length; i++){\n            for(int j = i+1; j < nums.length; j++){\n                if(nums[i] == nums[j] && (i*j)%k == 0){\n                    count++;\n                }\n            }\n        }\n        return count;\n    }\n}\n```
['Array', 'Java']