90pts help
查看原帖
90pts help
1365127
dendky楼主2024/12/8 20:01
#include <bits/stdc++.h>
using namespace std;
bool prime[100000005];
int ans, zz;
int f[1000005];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    long long l, q;
    cin>>l>>q;
    prime[1]=1;//特判
    for (int i=2; i*i<=l; i++){
        if (!prime[i]){
            for (int j=i*i; j<=l; j+=i){
                prime[j]=1;
            }//标记
        }
        //cout<<i<<" "<<j<<endl;
    }
    for (int i=1; i<=l; i++){
        if (!prime[i]){
            f[++zz]=i;
        }
    }
//排好了序再输出
    for (int i=1; i<=q; i++){
        long long k;
        cin>>k;
        cout<<f[k]<<endl;
    }
    return 0;
}
2024/12/8 20:01
加载中...