建议加强数据
查看原帖
建议加强数据
587684
corrupted_random楼主2022/1/14 15:34

数据太水!!

本蒟蒻不会写线性筛,写了埃氏筛,开了O2,AC

代码

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e8+5;
    int n, q, t, cnt, b[5761456];
    bool a[N]; 
    int main()
    {
        ios::sync_with_stdio(0);
        scanf("%d%d", &n, &q);
        a[0]=a[1]=1;
        for(int i=2; i*i<=n; i++)if(!a[i])for(int j=i*i; j<=n; j+=i)a[j]=1;
        for(int i=2; i<=n; i++)if(!a[i])b[cnt++]=i;
        for(int i=0; i<q; i++)
        {
            scanf("%d", &t);
            printf("%d\n", b[t-1]);
        }
        return 0;
    }
2022/1/14 15:34
加载中...