Given two integers left and right, return the count of numbers in the inclusive range [left, right] having a prime number of set bits in their binary representation.

Recall that the number of set bits an integer has is the number of 1's present when written in binary.


	For example, 21 written in binary is 10101, which has 3 set bits.


&nbsp;
Example 1:

Input: left = 6, right = 10
Output: 4
Explanation:
6  -&gt; 110 (2 set bits, 2 is prime)
7  -&gt; 111 (3 set bits, 3 is prime)
8  -&gt; 1000 (1 set bit, 1 is not prime)
9  -&gt; 1001 (2 set bits, 2 is prime)
10 -&gt; 1010 (2 set bits, 2 is prime)
4 numbers have a prime number of set bits.


Example 2:

Input: left = 10, right = 15
Output: 5
Explanation:
10 -&gt; 1010 (2 set bits, 2 is prime)
11 -&gt; 1011 (3 set bits, 3 is prime)
12 -&gt; 1100 (2 set bits, 2 is prime)
13 -&gt; 1101 (3 set bits, 3 is prime)
14 -&gt; 1110 (3 set bits, 3 is prime)
15 -&gt; 1111 (4 set bits, 4 is not prime)
5 numbers have a prime number of set bits.


&nbsp;
Constraints:


	1 &lt;= left &lt;= right &lt;= 106
	0 &lt;= right - left &lt;= 104


class Solution:
    def countPrimeSetBits(self, left: int, right: int) -> int:
        primes = {2, 3, 5, 7, 11, 13, 17, 19}
        return sum(bin(n).count('1') in primes for n in range(left, right + 1))
class Solution {
     public int calculateSetBits(String s){
        int count=0;
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i)=='1') count++;
        }
        return count;
    }

    public boolean isPrime(int n){
        if (n==0 || n==1) return false;
        for (int i = 2; i <= n/2; i++) {
            if(n%i ==0 ) return false;
        }
// System.out.println(n+" - ");
        return true;
    }

    public int countPrimeSetBits(int left, int right) {
        int count=0;
        for(int i=left;i<=right;i++){
            String b= Integer.toBinaryString(i);

            int n=calculateSetBits(b);

            if(isPrime(n)) count++;
        }
        return count;
    }
}
class Solution {
public:
    int countPrimeSetBits(int left, int right) {
        int ans=0;
        while(left<=right) {
            int cnt=__builtin_popcount(left);
            if(cnt==2 || cnt==3 || cnt==5 || cnt==7 || cnt==11 || cnt==13 || cnt==17 || cnt==19)
                ++ans;
            ++left;
        }
        return ans;
    }
};
/**
 * @param {number} L
 * @param {number} R
 * @return {number}
 */
var countPrimeSetBits = function(L, R) {
  let set = new Set([2, 3, 5, 7, 11, 13, 17, 19]);
  let countPrime = 0;
  
  for (let i = L; i <= R; i++) {
    if (set.has(i.toString(2).replace(/0/g, '').length)) countPrime++;
  }

  return countPrime;
};
Prime Number of Set Bits in Binary Representation