输不出来,求助

P3383 【模板】线性筛素数

liangcha_crush_ly @ 2024-08-28 22:34:20

rt

#include<iostream>

using namespace std;
int n,q,a[100001],x,answer[100001],cnt;
void find(int n){
    for(int i=2;i<=n;i++){
        if(a[i])continue;
        answer[++cnt]=i;
        for(int j=1;j<=cnt&&i*answer[j]<=n;j++){
            a[i*answer[j]]=1;
            if(i%answer[j]==0){
                break;
            }
        }
    }
    return;
}
signed main(){
    cin>>n;
    find(n);
    for(int i=1;i<=q;i++){
        scanf("%d",&x);
        printf("%d\n",answer[x]);
    }
    return 0;
}

by meifan666 @ 2024-08-28 22:35:41

@liangcha_crush 输入q呢?


by liangcha_crush_ly @ 2024-08-28 22:37:47

@meifan666 谢谢你的帮助,现在可输出了, 但输出有一部分错了(


by meifan666 @ 2024-08-28 22:38:33

@liangcha_crush a数组太小了,要到1e8


by meifan666 @ 2024-08-28 22:39:04

(实际上碍事筛都能过)


by liangcha_crush_ly @ 2024-08-28 22:44:50

@meifan666 已过,此贴结


|