ChasonWang @ 2024-07-30 13:36:05
rt
#include<bits/stdc++.h>
using namespace std;
bool st[10000005];
int a[10000005];
int main(){
std::ios::sync_with_stdio(0);
int n;
cin>>n;
int cnt=0;
for(int i=2;i<=n;i++){
if(!st[i]){
cnt++;
a[cnt]=i;
for(int j=0;j*i<=n;j++){
st[i*j]=1;
}
}
}
int q;
cin>>q;
while(q--){
int x;
cin>>x;
cout<<a[x]<<endl;
}
return 0;
}
by Down_syndrome @ 2024-07-30 13:39:35
开到
by _Mount_ @ 2024-07-30 13:57:19
我之前也RE过,筛的时候还要判断一下。
for(int i = 2;i*i<= n;i ++){
if(book[i]) continue;
else if(ip(i)){//判断是否是质数
for(int p = 2;p*i <= n;p ++){//不要从0开始
book[i*p] = true;
}
}
}
by JJLAW @ 2024-07-30 14:01:40
素数筛法