mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-25 12:14:26 +08:00
18 lines
319 B
Go
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
|
|
}
|