dev-c++不知出了什么问题……
  • 板块灌水区
  • 楼主shipeiqian
  • 当前回复27
  • 已保存回复27
  • 发布时间2022/7/16 12:42
  • 上次更新2023/10/27 20:04:06
查看原帖
dev-c++不知出了什么问题……
632063
shipeiqian楼主2022/7/16 12:42

问题↓

代码

#include <iostream>
#include <cstring>
using namespace std;
const int maxn=100000005;
typedef long long ll;
ll n,q,primes[maxn],st[maxn],cnt=0;
int main(){
	std::ios::sync_with_stdio(0);
	cin >>n;
	memset(st,0,sizeof(st));
	st[1]=0;
	for(int i=2;i<=n;i++){
    	if(st[i]){
        	primes[cnt++]=i;
        	for(int j=0;primes[j]*i<=n&&j<=cnt;j++){
            	st[primes[j]*i]=0;
            	if(i%primes[j]==0)break;
        	}
    	}
	}
	while(q--){
		int t;
		cin >>t;
		cout <<primes[t] <<endl;
	}
	return 0;
}

2022/7/16 12:42
加载中...