链接:
描述,示例和提示:
代码:
class Solution {
public:
unordered_set<int> prime = {2,3,5,7,11,13,17,19};
int countPrimeSetBits(int left, int right) {
int ans = 0;
for(int i = left; i <= right; i++) {
int cnt = __builtin_popcount (i);//__builtin_popcount统计一个数的二进制有多少个一
if(prime.count(cnt)) ans++;
}
return ans;
}
};