https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation/description/
题解:给出两个数L,R,要我们在【L,R】范围内找出其二进制数字1的个数是素数的数,并返回有多少个这样的数。
class Solution {
public int countPrimeSetBits(int L, int R) {
int countPrime = 0;
for(int i = L; i <= R; i++) {
int countBit = 0, num = i, j;
while(num != 0) {
if(num%2==1)
countBit++;
num /= 2;
}
for(j = 2; j < countBit; j++)
if(countBit%j == 0)
break;
if(j == countBit)
countPrime++;
}
return countPrime;
}
}