-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
30 lines (26 loc) · 751 Bytes
/
Solution.java
File metadata and controls
30 lines (26 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution {
public int countPrimeSetBits(int L, int R) {
int count = 0;
for (int i = L; i <= R; i++) {
int oneCount = 0, x = i;
while (x > 1) {
x &= x - 1;
oneCount++;
}
if (oneCount > 1) {
x = oneCount / 2;
boolean isPrime = true;
while (x > 1) {
if (oneCount % x == 0) {
isPrime = false;
break;
} else {
x--;
}
}
if (isPrime) count++;
}
}
return count;
}
}