|
发表于 2020-12-19 16:53:03
|
显示全部楼层
本楼为最佳答案
- def get_primes(n: int) -> list:
- """
- return a list containing all prime numbers less than n.
- """
- if n <= 2:
- return []
- isprime = [True for _ in range(n)]
- result = [2]
- for i in range(3, n, 2):
- if isprime[i]:
- result.append(i)
- for j in range(0, len(result)):
- if i * result[j] >= n:
- break
- isprime[i * result[j]] = False
- if i % result[j] == 0:
- break
- return len(result)
- lst=[]
- n=input()
- while n:
- n=int(n)
- lst.append(n)
- n=input()
- for n in lst:
- print(get_primes(n))
复制代码 |
|