C++ || EASY TO UNDERSTAND || Simple Code
\n#define ll long long \nclass Solution {\npublic:\n    long long countExcellentPairs(vector<int>& nums, int k) {\n        int n=nums.size();\n        vector<in
```\n#define ll long long \nclass Solution {\npublic:\n    long long countExcellentPairs(vector<int>& nums, int k) {\n        int n=nums.size();\n        vector<int> v;\n        set<int> st;\n        for(int &x:nums)\n        {\n            st.insert(x);\n        }\n        ll ans=0;\n        for(auto it=st.begin();it!=st.end();it++)\n        {\n            int c=0;\n            int num=*it;\n            for(int j=0;j<32;j++)\n            {\n                if(num&(1<<j))\n                {\n                    c++;\n                }\n            }\n            if(2*c>=k)\n            {\n                ans++;\n            }\n            v.push_back(c);\n        }\n        sort(v.begin(),v.end());\n        ll i,j;\n        i=0;\n        j=v.size()-1;\n        while(i<j)\n        {\n            if(v[i]+v[j]<k)\n            {\n                i++;\n                continue;\n            }\n            ans+=2*1ll*(j-i);\n            j--;\n        }\n        return ans;\n    }\n};\n```\n**Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome**\n
[]