fyc_LC @ 2024-11-16 00:10:14
先判断有没有超出
by KillElena @ 2024-12-07 16:02:50
什么意思@fyc_LC
by KillElena @ 2024-12-07 16:03:22
#include<bits/stdc++.h>
using namespace std;
long long zhishu[100001];
bool biaoji[1000001];
void zzs(int n){
int p;
memset(biaoji,1,sizeof(biaoji));
biaoji[0]=0;biaoji[1]=0;
for(int i=2;i<=n;i++){
if(biaoji[i]){
zhishu[++p]=i;
}
for(int j=1;j<=p&&i*zhishu[j]<=n;j++){
biaoji[i*zhishu[j]]=0;
if(i%zhishu[j]==0) break;
}
}
}
int main(){
std::ios::sync_with_stdio(0);
int n,q,x;
cin>>n>>q;
zzs(n);
while(q){
q--;
cin>>x;
cout<<zhishu[x-1]<<'\n';
}
return 0;
}
by KillElena @ 2024-12-07 16:03:57
@fyc_LC 帮我看看可以不
by fyc_LC @ 2024-12-07 22:04:12
@KillElena首先标记数组是是标记是否为合数且数组初始化为为0应标记成1具体可以看看oi wiki上的讲的比较好
by KillElena @ 2024-12-08 12:50:55
@fyc_LC 解决了但不知道为啥解决了,我只是把void zzs(int n)改成了int zzs(int n)然后让他返回了一个p,不知道为啥就不re了