ap
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\nint k1(int a)\n{\n    int cnt=0;\n    while(a)\n    {\n        cnt+=(a%2);\n        a/=2;\n    }\n    return cnt;\n}\nint ans=0;\nvoid l(int i,int j,vector<int> &t,int ini,int k)\n{\n   if(i>j)return;\n   int mid=i+(j-i)/2;\n\n   if(t[ini]+t[mid]>=k)\n   {\n    ans=mid;\n    l(i,mid-1,t,ini,k);\n   }else\n   {\n     l(mid+1,j,t,ini,k);\n   }\n}\n    long long countExcellentPairs(vector<int>& nums, int k) {\n        set<int> s;\n        for(auto i:nums)\n        {\n            s.insert(i);\n        }\n        vector<int> t;\n        for(auto i:s)\n        {\n            t.push_back(k1(i));\n        }\n        sort(t.begin(),t.end());\n        // for(auto i:t)cout<<i<<" ";\n        // cout<<endl;\n        long long an=0;\n        for(int i=0;i<t.size();i++)\n        {\n            if(t[i]>=k)\n            {\n                an+=t.size();\n                continue;\n            }else\n            {\n                ans=t.size();\n                l(0,t.size()-1,t,i,k);\n                //cout<<ans<<endl;\n                an+=t.size()-ans;\n            }\n        }\n        return an;\n    }\n};\n```
['C++']