90pts help

P3383 【模板】线性筛素数

dendky @ 2024-12-08 20:01:46

#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;
}

by dendky @ 2024-12-08 20:02:37

80 pts 本人口误


by 缪凌锴_Mathew @ 2024-12-09 19:22:09

@dendky f 数组开太小了,开 int f[6000005]; 就过了。


by dendky @ 2024-12-09 19:26:23

@缪凌锴_Mathewaz...谢谢大佬

|| @liangbowen : 达到22:30把电脑给蔡老/wx || @WRuperD : 不是,这么牛,达到24:00 吗 || @缪凌锴_Mathew : ucup,启动!

意外在别人犇里看见你了,嘻嘻


by dendky @ 2024-12-09 19:26:48

@缪凌锴_Mathew已关


|