Python 3  ||   8 lines, w/ example  ||    T/S: 89% / 90%
\nclass Solution:\n    def countExcellentPairs(self, nums: List[int], k: int) -> int:\n        \n        bits, ans = defaultdict(int), 0         #  Ex:  nums = 
```\nclass Solution:\n    def countExcellentPairs(self, nums: List[int], k: int) -> int:\n        \n        bits, ans = defaultdict(int), 0         #  Ex:  nums = [1,2,9,1,3,4,9]\n                                                #\n        for num in set(nums):                   #  set(nums) = {1, 2, 3, 4, 9}      \n            bits[num.bit_count()] += 1          #  no. of bits: 1  1  2  1  2  =>  bits = {1:3, 2:2}\n            \n        for i in bits:                          #    i   j  i+j>=k  ans\n            for j in bits:                      #   \u2013\u2013\u2013 \u2013\u2013\u2013 \u2013\u2013\u2013\u2013\u2013\u2013  \u2013\u2013\u2013\u2013\u2013\u2013\u2013\u2013\n                if i + j >= k:                  #    1   1   False    0\n                    ans+= bits[i] * bits[j]     #    1   2   True     0 + 3*2 = 6\n                                                #    2   1   True     6 + 2*3 = 12\n        return ans                              #    2   2   True    12 + 2*2 = 16 <-- ans    \n```\n[https://leetcode.com/problems/number-of-excellent-pairs/submissions/1287401501/](https://leetcode.com/problems/number-of-excellent-pairs/submissions/1287401501/)\n\nI could be wrong, but I think that time complexity is *O*(*M* + *N* ^2) and space complexity is *O*(*M* + *N*), in which *M* ~ `len(nums)` and  *N* ~ log(max(*nums*). \n\n
['Bit Manipulation', 'Python']