C++ easy binary search solution
\nclass Solution {\npublic:\n     long long countSetBits(long long n)\n    {\n        long long count = 0;\n        while (n) {\n            n &= (n - 1);\n    
```\nclass Solution {\npublic:\n     long long countSetBits(long long n)\n    {\n        long long count = 0;\n        while (n) {\n            n &= (n - 1);\n            count++;\n        }\n         \n        return count;\n    }\n    \n    long long countExcellentPairs(vector<int>& nums, int k) {\n        \n        sort(nums.begin(), nums.end());\n\t\t\n        auto ip = unique(nums.begin(), nums.end());  \n        nums.resize(distance(nums.begin(), ip));\n\t\t//  It removes all the adjacent similar elements from the vector giving us the distinct elements. (make sure to sort first).\n         \n     \n        vector<int> vec;\n        long long n = nums.size();\n        for (long long i = 0 ; i < n ; i++){\n            vec.push_back(countSetBits(nums[i])); // count set bits in each element.\n        }\n        \n        sort(vec.begin(), vec.end()); \n        \n        long long result = 0;\n        n = vec.size();\n        \n        for (long long i = 0; i < vec.size() ; i++){\n            long long val = vec[i];\n            \n            long long idx = lower_bound(vec.begin(), vec.end(), max(k - val, 0LL)) - vec.begin();  \n\t\t\t// max(k - val, 0LL))  to handle values that are greater than k hence total no. of pairs they can make is from index 0 to all values till n.\n            \n\t\t\tresult += n - idx;\n\t\t\t// adding total pairs that single value can make. \n        }\n        \n        return result;\n        \n    }\n};\n```
['C', 'Binary Tree']