CPP | Easy Solution
Let f(n)=number of set bits in n\nThen\nf(a|b)=f(a)+f(b)-f(a&b). ....(1)\nNow we need\nf(a|b)+f(a&b)>=k\nUsing equation 1\nf(a)+f(b)>=k.\n\nNow we can solve usi
Let f(n)=number of set bits in n\nThen\nf(a|b)=f(a)+f(b)-f(a&b). ....(1)\nNow we need\nf(a|b)+f(a&b)>=k\nUsing equation 1\nf(a)+f(b)>=k.\n\nNow we can solve using bruteforce by storing elements that have f(x)=i\n\nCode based on the above idea\n```cpp\nclass Solution {\n    int set_bits(int n)\n    {\n        int k=0;\n        while(n>0)\n        {\n            k+=n%2;\n            n=n/2;\n        }\n        return k;\n    }\n    \npublic:\n    long long countExcellentPairs(vector<int>& nums, int k) {\n        long long ans=0ll;\n        vector<long long> freq(40,0);\n        set<int> s;\n        \n        for(auto ele : nums)\n            s.insert(ele);\n        \n        for(auto ele : s)\n        {\n            int temp=set_bits(ele);\n            freq[temp]++;\n        }\n        \n        for(auto ele : s)\n        {\n            int temp=set_bits(ele);\n            int t=ans;\n            for(int i=std::max(0,k-temp);i<40;i++)\n                ans=ans+freq[i];\n        }\n        return ans;\n    }\n};\n```
['Bit Manipulation', 'C++']