Skip to content

Commit 685814d

Browse files
committed
Time: 4 ms (55.49%), Space: 8 MB (61.81%) - LeetHub
1 parent add574a commit 685814d

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int prime(int n)
4+
{
5+
if(n<=1)return false;
6+
for(int i=2;i*i<=n;++i)
7+
{
8+
if(n%i==0)return 0;
9+
}
10+
return 1;
11+
}
12+
int countPrimeSetBits(int left, int right) {
13+
int ans=0;
14+
for(int i=left;i<=right;++i)
15+
{
16+
int bt=__builtin_popcount(i);
17+
if(prime(bt))ans++;
18+
}
19+
return ans;
20+
}
21+
};

0 commit comments

Comments
 (0)