__owen__ @ 2024-12-29 12:14:22
为什么内存爆了啊??
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define int long long
const int N = 1e8 + 10;
using namespace std;
vector<int> init(int n){
vector<int> isprime(N + 1,true);
vector<int> prime;
for(int i = 2; i <= n; i++){
if(isprime[i])
prime.push_back(i);
for(int j = 0; j < prime.size() && i * prime[j] <= n; j++){
isprime[i * prime[j]] = false;
if(i % prime[j] == 0)
break;
}
}
return prime;
}
signed main() {
IOS;
int n,m;
cin>>n>>m;
vector<int> ans = init(n);
while(m--){
int t;cin>>t;
cout << ans[t - 1] << endl;
}
return 0;
}
by LXcjh4998 @ 2024-12-29 12:26:35
显然 int
数组并不能开
@__owen__
by LXcjh4998 @ 2024-12-29 12:45:56
应当使用 bool
数组。
@__owen__
by __owen__ @ 2025-01-06 21:30:53
@LXcjh4998好的好的,谢谢