| 1 | class Solution { |
| 2 | public int tupleSameProduct(int[] nums) { |
| 3 | HashMap<Integer, Integer> productMap = new HashMap<>(); |
| 4 | int n = nums.length; |
| 5 | for(int i=0;i<n;i++){ |
| 6 | for(int j=i+1;j<n;j++){ |
| 7 | int res = nums[i] * nums[j]; |
| 8 | productMap.put(res, productMap.getOrDefault(res,0)+1); |
| 9 | } |
| 10 | } |
| 11 | int ans=0; |
| 12 | for(Map.Entry<Integer, Integer> entry : productMap.entrySet()){ |
| 13 | int product = entry.getKey(); |
| 14 | int count = entry.getValue(); |
| 15 | if(count>=2){ |
| 16 | int comb = (count * (count-1))/2; |
| 17 | ans = ans + comb*8; |
| 18 | } |
| 19 | } |
| 20 | return ans; |
| 21 | } |
| 22 | } |