[单选题]

```import math
def sieve(size):
sieve= [True] * size
sieve[0] = False
sieve[1] = False
for i in range(2, int(math.sqrt(size)) + 1):
k= i * 2
while k < size:
sieve[k] = False
k += i
return sum(1 for x in sieve if x)
print(sieve(10000000000))```

• `455052510`
• `455052511`
• `455052512`
• `455052513`

```@numba.jit()
def cur(size):
sieve = [True] * size
sieve[0] = False
sieve[1] = False
if size == 2:
return sieve
factor = [index for index, val in enumerate(cur(int(math.sqrt(size)+1))) if val]
for i in factor:
k = i * 2
while k < size:
sieve[k] = False
k += i
return sieve

def up(size):
sieve = cur(size)
return sum(1 for x in sieve if x)```

`@numba.jit()`

N比较小的时候，再烂的算法怎么也能跑出来，N很大的时候，没有好的算法还是不要轻易尝试了😂😂。

```import math def sieve(size):
sieve= [True] * size
sieve[0] = False  sieve[1] = False  for i in range(2, int(math.sqrt(size)) + 1):
k = i * 2  while k < size:
sieve[k] = False  k += i return sum(1 for x in sieve if x) print(sieve(100))```

zzzz

13条回答 4259浏览

# 相关试题

• 扫描二维码，关注牛客网

• 下载牛客APP，随时随地刷题