求调,RE*5

P3383 【模板】线性筛素数

xhxxwcr @ 2024-08-05 09:42:17

#include<bits/stdc++.h>
using namespace std;
int prime[1000010];
bool not_p[100000000];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(), cout.tie();
    int n,m;
    cin >> n >> m;
    int cnt = 1;
    not_p[0] = 1;
    not_p[1] = 1;
    for(int i = 2;i <= n;i++){
//      if(not_p[i])  continue;
        if(not_p[i] == 0)  prime[cnt++] = i;
        for(int j = 1;j <= cnt && i * prime[j] <= n;j++){
            not_p[i * prime[j]] = 1;
            if(i % prime[j] == 0)  break;
        }
    }
    for(int i = 1;i <= m;i++){
        int a;
        cin >> a;
        cout << prime[a] << endl;
    }
}

by xhxxwcr @ 2024-08-05 09:43:14

好玄学,我同学的n log log n能过,我的n不能过……


by QWQ_HY_DFX @ 2024-08-05 09:53:25

@xhxxwcr 数组开小了

还有你同学写的是埃氏筛吧

by QWQ_HY_DFX @ 2024-08-05 09:54:55

@xhxxwcr 对了,其实埃氏筛是O(n \ln \ln n)的(

不过写log也没啥影响


by xhxxwcr @ 2024-08-05 09:58:26

@QWQ_HY_DFX ok,过了,谢


|