LeetCode-【数学】判断素数

480 ワード

leetcode 204タイトルリンク:質量数の計算
エラドセふるいほう
def countPrimes(self, n):
        """
        :type n: int
        :rtype: int
        """
        if n < 2:
            return 0
        res = 0
        arr = [0] * (n)
        for i in range(2,n):
            if arr[i] == 0:
                res+=1
                j = 1
                while j*i < (n):
                    arr[i*j]=1
                    j+=1
        return res