yuniko_n @ 2024-03-28 14:08:54
import java.util.*;
public class Main{
static int n,m;
static boolean []a=new boolean[100000002];//存范围
static int []b=new int[10000002];//存质数
//欧拉筛
public static void prime() {
int flag=1;
for(int i=2;i<=n;i++) {
if(!a[i]) {
b[flag]=i;
flag++;
}
for(int j=1;j<=flag&&i*b[j]<=n;j++) {
a[i*b[j]]=true;
if(i%b[j]==0)
break;
}
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
m=sc.nextInt();
prime();//预处理
for(int i=1;i<=m;i++) {
int x=sc.nextInt();
System.out.println(b[x]);
}
}
}
by SpeedStar @ 2024-03-28 14:27:46
@yuniko_n 肯定要快读啊
by yuniko_n @ 2024-03-29 00:49:18
@寒烟冷浅暮殇 解决了,谢谢大佬!