[Java] Easy and understandable solution || Bit Manipulation || Binary Search
\nclass Solution {\n    public long countExcellentPairs(int[] nums, int k) {\n        Set<Integer> set = new HashSet<>();\n        for(int n: nums) set.add(n);\
```\nclass Solution {\n    public long countExcellentPairs(int[] nums, int k) {\n        Set<Integer> set = new HashSet<>();\n        for(int n: nums) set.add(n);\n        \n        List<Integer> list = new ArrayList<>();\n        for(int n: set){\n            list.add(getBitCount(n));\n        }\n        Collections.sort(list);\n        long res = 0;\n        for(int i = 0; i< list.size(); i++){\n            int lo = i, hi = list.size()-1;\n            long cur = list.size();\n            while(lo <= hi){\n                int md = lo + (hi - lo)/2;\n                if(list.get(md) + list.get(i) >=k){\n                    cur = md;\n                    hi = md - 1;\n                }else{\n                    lo = md + 1;\n                }\n            }\n            res += 2 * (list.size() - cur);\n            if(i == cur) res -= 1;\n        }\n        return res;\n    }\n    \n    private int getBitCount(int n){\n        int count = 0;\n        while(n!=0){\n            count += (n&1);\n            n>>=1;\n        }\n        return count;\n    }\n}\n\n```
['Binary Search', 'Bit Manipulation', 'Binary Tree', 'Ordered Set', 'Java']