c++  two sum variation
\nonly important thing to observe is \n(number of set bit of (A & B) )+(number of set bit of (A | B))= number of set bit in A +number of set bit in B\nbecause\n
```\nonly important thing to observe is \n(number of set bit of (A & B) )+(number of set bit of (A | B))= number of set bit in A +number of set bit in B\nbecause\nA&B=common set_bit in A and  B (let say X)\nA|B =number of set bit in A + number of set bit in B - common set_bit in A and B(X) \n after adding these\n A&B +A|B =number of set bit in A + number of set bit in B + X - X \n A&B +A|B=number of set bit in A + number of set bit in B \n \n```\n \n```\n \n \n class Solution {\npublic:\n    int num_set_bit(int num)\n    {\n        int cnt=0;\n        while(num)\n        {\n            if(num&1)\n            {\n                cnt++;\n            }\n            num=num>>1;\n        }\n        return cnt;\n    }\n    long long countExcellentPairs(vector<int>& nums, int k) {\n        vector<int>v;\n        set<pair<int,int>>s;\n        for(auto x:nums)\n        {\n            int val=num_set_bit(x);\n            if(s.find({val,x})==s.end())\n            {\n                s.insert({val,x});\n                v.push_back(val);\n            }\n        }\n        sort(v.begin(),v.end());\n        // (a+b>=k)\n        long long int ans=0;\n        for(int i=0;i<v.size();i++)\n        {\n            int x=k-v[i];\n            auto it=lower_bound(v.begin(),v.end(),x);\n            if(it!=v.end())\n            {\n                int idx=it-v.begin();\n                ans+=(v.size()-idx)*1LL;\n            }\n        }\n        return ans;\n    }\n};\n```\n
[]