c++#1,#3,#5WA,大佬求助
查看原帖
c++#1,#3,#5WA,大佬求助
1052465
Mirrol楼主2023/10/3 15:27
#include<iostream>
using namespace std;
bool pot(long long n);
int main(){
	int n;cin>>n;
	long long SUM=0;
	if(n==1){
		cout<<"0";
		return 0;
	}
	for(int i=2,ix=0;i<n;i++){
		if(pot(i)==true) SUM+=i;
		if(SUM==n){
			cout<<i<<endl;
			cout<<ix+1;
			return 0;
		}
		if(SUM>n){
			cout<<ix;
			return 0;
		}
		if(pot(i)==true){
			ix++;
			cout<<i<<endl;
		}
	}
}
bool pot(long long n){
	if(n==2) return true;
	for(int i=2;i<n;i++){
		if(n%i==0){
			return false;
		}
	}

2023/10/3 15:27
加载中...