欧拉筛MLE求助!0ptsQAQ
查看原帖
欧拉筛MLE求助!0ptsQAQ
797229
inarticulate_stupid楼主2023/6/29 11:38
#include<bits/stdc++.h>
using namespace std;
const long long N=1e8;
long long n,q,a[N],b[N],p,d,x;
bool f[N];
signed main(){
    std::ios::sync_with_stdio(0);
	cin>>n>>q;
	for(int i=2;i<=n;i++){
		if(!f[i])a[++p]=i,b[++d]=i;
		for(int j=1;j<=p;j++)
		{
			f[a[j]*i]=1;
			if(i%a[j]==0)break;
		}
	}
	while(q--){
		cin>>x;
		cout<<b[x]<<endl;
	}
	return 0;
}
2023/6/29 11:38
加载中...