生成质数

2020-08-14  本文已影响0人  晨光523152
def countPrimes(n: int) -> int:
        res = []
        for i in range(2, n+1):
            for j in range(2, int(i ** 0.5) + 1)##for j in range(2,i):
                if i % j == 0:
                    break
            else:
                # print(i)
                res.append(i)
        return res

参考资料:
https://leetcode-cn.com/problems/count-primes/solution/qiu-zhi-shu-chao-guo-90-by-powcai/

上一篇 下一篇

猜你喜欢

热点阅读