0分求助,回答者必关!
查看原帖
0分求助,回答者必关!
575138
xiongty2024楼主2023/10/3 16:51
#include<bits/stdc++.h>
using namespace std;
int n,q,t,cnt;
bool isprime(int x)
{
	if(x<2) return false;
	for(int i=2;i*i<=x;i++)
		if(x%i==0)
			return false;
	return true;
}
int main()
{
	std::ios::sync_with_stdio(0);
	int i,j;
	cin>>n>>q;
	for(i=1;i<=q;i++)
	{
		cin>>t;
		cnt=0;
		for(j=2;j<=n;j++)
			if(isprime(j))
			{
				cnt++;
				if(cnt==t)
				{
					cout<<j<<endl;
					break;
				}
			}
	}
	return 0;
}

rt

2023/10/3 16:51
加载中...