20分RE,WA
查看原帖
20分RE,WA
768270
__why楼主2023/11/11 09:04
#include<bits/stdc++.h>
using namespace std;
vector<int>p;
int leastp[100000008];
void init(int n){
	for(long long i = 2;i<=n;++i) if(leastp[i]==0){
		p.push_back(i);
		leastp[i] = i;
		for(long long j = i*i;j<=n;j+=i){
			if(leastp[j] == 0){
				leastp[j] = i;
			}
		}
	}
}
bool isprime(int x) {
    if (x == 0 || x == 1) return false;
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}
int main(){
	int n,sum,cnt=0;
	cin>>n;
	int i = 0;
	init(n);
	do{
		cout<<p[i]<<endl;
		sum+=p[i];
		cnt++;
		i++;
	}while(sum<n);
	cout<<cnt;
}

啊啊啊大佬求调

2023/11/11 09:04
加载中...