社区讨论

RE???

P3383【模板】线性筛素数参与者 3已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@mlnq7z6f
此快照首次捕获于
2026/02/15 20:33
4 天前
此快照最后确认于
2026/02/16 16:08
3 天前
查看原帖
谁能帮助我解释一下为什么RE?
代码如下:
CPP
#include<bits/stdc++.h>
using namespace std;
vector<int> prime;
bool is_prime[20000005];
void Eratosthenes(int n) {
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; ++i) is_prime[i] = true;
  for (int i = 2; i <= n; ++i) {
    if (is_prime[i]) {
      prime.push_back(i);
      if ((long long)i * i > n) continue;
      for (int j = i * i; j <= n; j += i)
        is_prime[j] = false; 
    }
  }
}
void solve(){
    int k;
     std::ios::sync_with_stdio(0);
    cin>>k;
    cout<<prime[k-1]<<'\n';
    return ;
}
int main(){
    int n,q;
    std::ios::sync_with_stdio(0);
    cin>>n>>q;
    Eratosthenes(n);
    while(q--)solve();
    return 0;
}

回复

3 条回复,欢迎继续交流。

正在加载回复...