34 lines
421 B
Go
34 lines
421 B
Go
package q762
|
|
|
|
var isPrime = [21]bool{}
|
|
|
|
func init() {
|
|
for _, n := range []int{
|
|
2, 3, 5, 7, 11, 13, 17, 19,
|
|
} {
|
|
isPrime[n] = true
|
|
}
|
|
}
|
|
|
|
func count1s(n int) int {
|
|
cnt := 0
|
|
for n > 0 {
|
|
if n%2 == 1 {
|
|
cnt++
|
|
}
|
|
n >>= 1
|
|
}
|
|
return cnt
|
|
}
|
|
|
|
func countPrimeSetBits(left, right int) int {
|
|
cnt := 0
|
|
for n := left; n <= right; n++ {
|
|
if isPrime[count1s(n)] {
|
|
cnt++
|
|
}
|
|
}
|
|
return cnt
|
|
}
|
|
|
|
var _ = countPrimeSetBits
|