MC_xjhjdA @ 2024-08-18 11:33:27
def oss(n):
z=[True for _ in range(n+1)]
p=2
while (p*p<=n):
if (z[p]==True):
for i in range(p*p,n+1,p):
z[i]=False
p+=1
zl=[]
for p in range(2,n+1):
if z[p]:
zl.append(p)
return zl
n,q=map(int,input().split())
l=oss(n)
o=[]
for _ in range(q):
o.append(l[int(input())-1])
for x in range(q):
print(o[x])
by QAQ_liu @ 2024-08-18 11:37:01
@MC_xjhjdA 额,你有没有发现大家基本上都是学c++的 (看不懂)
by _zhang @ 2024-08-18 11:39:12
@MC_xjhjdA Py的时间空间太容易卡了,建议换成c/c++
by _zhang @ 2024-08-18 11:41:31
while (p*p<=n):
if (z[p]==True):
for i in range(p*p,n+1,p):
z[i]=False
p+=1
这里看着更像埃氏筛啊,不像线性筛
by MC_xjhjdA @ 2024-08-18 11:48:03
@_zhang 啊这是欧式筛(
by MC_xjhjdA @ 2024-08-18 11:48:32
@_zhang 只会python3
by _zhang @ 2024-08-18 11:53:17
@MC_xjhjdA 你欧拉筛不是枚举
by AK_hai @ 2024-08-18 11:53:31
?(本人刚好会python2)好像帮不到忙
by _zhang @ 2024-08-18 11:54:11
(雾
by AK_hai @ 2024-08-18 11:55:20
准确来说python2在python3的基础就是去掉括号
by _zhang @ 2024-08-18 12:00:16
@AK_hai 赶紧学学Py3吧,Py2早过时了