Problem :

https://leetcode.com/problems/count-primes/


My Solution :

class Solution:
def countPrimes(self, n):
"""
:type n: int
:rtype: int
"""
is_prime = [1]*n
for i in range(2, int(n**0.5)+1):
if is_prime[i]:
for j in range(i**2, n, i):
is_prime[j] = 0
return sum(is_prime[2:])


Comment :

에라토스테네스의 체 문제이다.

secret