听灌多
  • 板块灌水区
  • 楼主Lastheart
  • 当前回复5
  • 已保存回复5
  • 发布时间2024/10/28 20:02
  • 上次更新2024/10/28 21:35:40
查看原帖
听灌多
979476
Lastheart楼主2024/10/28 20:02

P3383 0分TLE

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e8+10;
ll n,q,a[N],x=1,k;
bool isPrime(int n)
{   
 	if(n<=1)
    { 
		return false; 
	} 
 	for(int i=2;i*i<=n;i++)
    { 
 		if(n%i==0)
  { 
 			return false; 
		} 
	} 
 	return true; 
} 
int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    cin>>n>>q;
    for(int i=2;i<=n;i++)
    {
    	if(isPrime(i))
    	{
    		a[x]=i;
    		x++;
    	}
    }
    while(q--)
    {
    	cin>>k;
    	cout<<a[k]<<endl;
    }
    return 0;
}
2024/10/28 20:02
加载中...