Simple Java Solution with Explanation - Bitwise Operator Equation
\nclass Solution {\n    \n    Map<Integer, Integer> setBitsDP = new HashMap<>();\n    \n    public long countExcellentPairs(int[] nums, int k) {\n        \n    
```\nclass Solution {\n    \n    Map<Integer, Integer> setBitsDP = new HashMap<>();\n    \n    public long countExcellentPairs(int[] nums, int k) {\n        \n        /*\n        countSetBits(a & b) = count set bits of a + count set bits of b - common set bits between a and b\n        countSetBits(a | b) = common set bits between a and b\n        countSetBits(a & b) + countSetBits(a | b) = countSetBits(a) + countSetBits(b)\n        */\n        Map<Integer, Set<Integer>> container = new HashMap<>();\n        for (int num : nums) {\n            int currCount = Integer.bitCount(num);\n            container.putIfAbsent(currCount, new HashSet<>());\n            container.get(currCount).add(num);\n        }\n        \n        // since Integer is 32 bits\n        long ans = 0;\n        for (int i = 1; i < 32; i++) {\n            for (int j = i; j < 32; j++) {\n                if (container.containsKey(i) && container.containsKey(j) && (i + j) >= k) {\n                    if (i == j) {\n\t\t\t\t\t    // count only once like (3, 3)\n                        ans += (long)(container.get(i).size() * container.get(j).size());\n                    } else {\n                        // both ways permutation like (1, 2) and (2, 1)\n                        ans += (long)(container.get(i).size() * container.get(j).size() * 2);\n                    }\n                }\n            }\n        }\n        \n        return ans;\n    }\n}\n```
['Java']