204. Count Primes
class Solution:
def isPrimeNumber(self, n):
for i in range(2, int(n**0.5)+1):
if n % i == 0:
return False
return n > 1
def countPrimes(self, n: int) -> int:
count = 0
for i in range(n):
if self.isPrimeNumber(i):
count += 1
return count質數篩
Last updated