线性筛40分求调
查看原帖
线性筛40分求调
577263
sea_bird楼主2024/10/15 13:39
#include<bits/stdc++.h>

using namespace std;
long long n,m,cnt=0,y;
bool num[100000005];
long long x[100000005];
void prime(long long a){
	for(long long i=2;i<=a;i++){
		if(!num[i]){
			x[++cnt]=i;
			
			for(long long j=2;i*j<=a;j++){
				num[i*j]=true;
			}
		}
		
	}

}

int main(){
	
	//freopen("P3383_1.in","r",stdin); //以只读方式打开输入文件test.in 
    //freopen("P3383_1.out","w",stdout); //以写入方式打开输出文件test.out 
    ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	prime(n);
	while(m--){
		cin>>y;
		cout<<x[y]<<endl;
	}
	//fclose(stdin);fclose(stdout); //关闭输入、输出文件 
	return 0;
}

2024/10/15 13:39
加载中...