题目:
题解:
func countPrimes(n int) int {primes := []int{}isPrime := make([]bool, n)for i := range isPrime {isPrime[i] = true}for i := 2; i < n; i++ {if isPrime[i] {primes = append(primes, i)}for _, p := range primes {if i*p >= n {break}isPrime[i*p] = falseif i%p == 0 {break}}}return len(primes)
}