Python Simple Solution
\nclass Solution:\n    def countExcellentPairs(self, nums: List[int], k: int) -> int:\n        nums.sort()\n        mapp = defaultdict(set)\n        ans = 0\n  
```\nclass Solution:\n    def countExcellentPairs(self, nums: List[int], k: int) -> int:\n        nums.sort()\n        mapp = defaultdict(set)\n        ans = 0\n        last = None\n        for i in nums:\n            if i==last:\n                continue\n            b = format(i,\'b\').count(\'1\')\n            mapp[b].add(i)\n            t = k-b\n            for j in range(max(0,t),31):\n                ans+=len(mapp[j])*2\n                if i in mapp[j]:\n                    ans-=1\n            last = i\n        return ans\n```
['Python', 'Python3']