Files
LeetCode-Go/leetcode/0762.Prime-Number-of-Set-Bits-in-Binary-Representation/762. Prime Number of Set Bits in Binary Representation.go
2020-08-07 17:06:53 +08:00

18 lines
319 B
Go

package leetcode
import "math/bits"
func countPrimeSetBits(L int, R int) int {
counter := 0
for i := L; i <= R; i++ {
if isPrime(bits.OnesCount(uint(i))) {
counter++
}
}
return counter
}
func isPrime(x int) bool {
return x == 2 || x == 3 || x == 5 || x == 7 || x == 11 || x == 13 || x == 17 || x == 19
}