题解看到的,有点不懂,为啥bitset用在欧拉筛上反而比埃氏筛还慢了,也比原来用bool数组慢
#include<bits/stdc++.h>
using namespace std;
const int N=1e8+6;
int n,q,prime[N],cnt;
bitset<N> st;
void iget(int x)
{
for(int i=2;i*i<=x;++i)
{
if(!st[i])
{
for(int j=i*i;j<=x;j+=i) st[j]=1;
}
}
for(int i=2;i<=x;++i)
{
if(!st[i]) prime[++cnt]=i;
}
}
void get(int x)
{
for(int i=2;i<=x;++i)
{
if(!st[i]) prime[++cnt]=i;
for(int j=1;prime[j]*i<=x&&j<=cnt;++j)
{
st[prime[j]*i]=1;
if(i%prime[j]==0) break;
}
}
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>n>>q;
iget(n);
while(q--)
{
int k;cin>>k;
cout<<prime[k]<<endl;
}
}