求助,全RE!
查看原帖
求助,全RE!
534589
S_Kuroko楼主2024/4/10 21:07
#include<bits/stdc++.h>
using namespace std;

bool numlist[100000050];
int prime[20000001],cnt;
int n,q;

void work(int n)
{
	for(int i=2;i<=n;i++)
	{
		if(numlist[i]==false)
		{
			prime[++cnt]=i;
			for(int j=i;i*j<n;j++)
			{
				numlist[i*j]=true;
			}
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	work(n);
	for(int i=1;i<=q;i++)
	{
		int k;
		cin>>k;
		cout<<prime[k]<<endl;
	}
	return 0;
} 
2024/4/10 21:07
加载中...