RE 求调

P3383 【模板】线性筛素数

s09236 @ 2024-10-05 16:21:13

#include<bits/stdc++.h>
using namespace std;
const int N=1e8+5;
int n,m;
bool vis[N/10];
long long prime[N/10],tot;
int main(){
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    for(int i=2;i<=n;i++){
        if(!vis[i]){
            prime[++tot]=i;
        }
        for(int j=1;j<=tot&&prime[j]<=n/i;j++){
            vis[i*prime[j]]=1;
            if(i%prime[j]==0){
                break;
            }
        }
    }
    for(int i=1;i<=m;i++){
        int a;
        cin>>a;
        cout<<prime[a]<<"\n";
    }
}

by untitled_cpp @ 2024-10-05 16:22:22

@s09236 听课


by liujinxv123 @ 2024-10-05 16:25:42

你N/10干嘛呀


by untitled_cpp @ 2024-10-05 16:25:50

@s09236 ll数组不能开1e8


by liujinxv123 @ 2024-10-05 16:27:31

还有,建议将prime数组改成vector

bool数组改成bitset


by Hollow_Knight @ 2024-10-05 16:28:21

@untitled_cpp false,正常都可以


by untitled_cpp @ 2024-10-05 16:29:07

@Hollow_Knight 好八


by Hollow_Knight @ 2024-10-05 16:30:13

@s09236 数组开1e8就行了


by s09236 @ 2024-10-05 16:32:42

@Hollow_Knight 已解决,已关


by H_first @ 2024-10-12 20:25:02

@Hollow_Knight 不是q次询问吗?数组开到1e6不行吗?


by H_first @ 2024-10-12 20:31:58

@Hollow_Knight 没事了,我一时脑子没在线。。。。


| 下一页