add new solutions

This commit is contained in:
Yiyang Kang 2026-03-01 13:45:00 +09:00
parent ee1868a10e
commit 2012261d3d
7 changed files with 205 additions and 0 deletions

View file

@ -0,0 +1,34 @@
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