class Solution { public: bool IsPrime(int n) { if (n == 1) { return false; } if (n == 2 || n == 3) { return true; } for (int i = 2; i <= sqrt(n); i++) { if (n%i == 0) { return false; } } return true; } int CountOnes(int n) { int sum = 0; while (n) { int x = n & 1; if (x) { sum++; } n >>= 1; } return sum; } int countPrimeSetBits(int L, int R) { int sum = 0; for (int i = L; i <= R; i++) { int x = CountOnes(i); if (IsPrime(x)) { sum++; } } return sum; } };