怎么就MLE了?
查看原帖
怎么就MLE了?
1616821
__owen__楼主2024/12/29 12:14

为什么内存爆了啊??

#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;
}
2024/12/29 12:14
加载中...