6.最大的质数
2025-03-16 22:08:14
发布于:广东
18阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int main() {
const int M=1e6;
vector<bool> p(M+1,1);
for(int i=2;ii<=M;++i){
if(p[i]){
for(int j=ii;j<=M;j+=i){
p[j]=0;
}
}
}
vector<int> mp(M+1);
int c=0;
for(int i=2;i<=M;++i){
mp[i]=(p[i]?c=i:c);
}
int q,n;
cin>>q;
while(q-- && cin>>n){
cout<<mp[n-1]<<'\n';
}
}
这里空空如也
有帮助,赞一个