爆零求助
查看原帖
爆零求助
619201
Mystical12楼主2023/8/11 21:18
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve();
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    //int t;cin>>t;while(t--){solve();}
    return 0;
}
int n,m,ans;
int v[100000001];
bool vis[100000001];
void solve(){
    scanf("%d%d",&n,&m);
    v[1]=1;
    for(int i=2;i<=n;i++)
    {
        if(!vis[i])v[++ans]=i;
        for(int j=1;j<=ans&&i*v[j]<=n;j++)
        {
            vis[v[j]*i]=1;
            if(i%v[j]==0)break;
        }
    }
    while(m--){
        int t;
        scanf("%d",&t);
        printf("%d\n",v[t]);
    }
    cout<<'\n';
}

2023/8/11 21:18
加载中...