C++求助
查看原帖
C++求助
1210473
ytezwsw_xjy楼主2024/3/19 21:46

我这个11和100都过不了,有大佬来看看吗(^▽^)

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,s=0,b=1,s1=0,s2=0;
	cin>>a;
	if(a%2!=0){
		s=a+1;
	}else{
		s=a;
	}
	for(int i=2;i<=s;i++){
		for(int j=2;j<=i-1;j++){
			if(i%j==0){
				b=0;
			}
		}
		if(b==1){
			s2=a-i;
		}
		if(b==1 && s2>=0){
			cout<<i<<endl;
			s1+=1;
			a-=i; 
		}
	}
	cout<<s1;
return 0;
}

2024/3/19 21:46
加载中...