13539173797zc @ 2025-01-05 15:55:28
我嘞个豆
#include<iostream>
using namespace std;
int a[1000010];
bool f(int a){
if(a==1||a==0) return 0;
for(int i=2;i*i<=a;i++){
if(a%i==0) return 0;
}
return 1;
}
int main(){
int n,q,k;
cin>>n>>q;
int j=1;
for(int i=2;i<=n;i++){
if(f(i)!=0) a[j]=i,j++;
}
for(int i=1;i<=q;i++){
cin>>k;
cout<<a[k]<<endl;
}
return 0;
}
by Folden_xiaoming @ 2025-01-05 16:00:33
埃氏筛做线性筛题,t了不是你的错是谁的?
by _lxc__ @ 2025-01-05 16:13:47
用筛法
by craftmine @ 2025-01-05 16:18:41
可以卡常过
by 13539173797zc @ 2025-01-05 16:26:37
@_lxc__就是想偷懒,而且我不会
by 13539173797zc @ 2025-01-05 16:27:56
@craftmine??啊?