limingyue @ 2024-09-27 18:43:33
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=0x3f3f;
int n,m;
int a[N];
bool is(int q){
for(int i=1;i*i<=q;i++)
if(q%i==0)
return false;
return true;
}
int main(){
cin>>n;
if(is(n-4)){
cout<<2<<" "<<2<<" "<<n-4<<endl;
}
for(int i=3;i<=n;i+=2){
for(int j=i;j<=n;j+=2){
if(is(i)){
if(is(j)){
if(is(n-i-j)){
if(i<=j&&j<=n-i-j){
cout<<i<<" "<<j<<" "<<n-i-j<<"\n";
break;
}
}
}
}
}
}
return 0;
}
by XiaoHongChong @ 2024-09-27 18:57:07
@limingyue
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=0x3f3f;
int n,m;
int a[N];
bool is(int q){
for(int i=2;i*i<=q;i++)
if(q%i==0)
return false;
return true;
}
int main(){
cin>>n;
if(is(n-4)){
cout<<2<<" "<<2<<" "<<n-4<<endl;
return 0; //这里要直接结束
}
for(int i=2;i<=n;i++){ //老老实实的计算,不需要优化也能AC
for(int j=i;j<=n;j++){ //同上
if(is(i)){
if(is(j)){
if(is(n-i-j)){
if(i<=j&&j<=n-i-j){
cout<<i<<" "<<j<<" "<<n-i-j<<"\n";
return 0; //这里要直接结束
}
}
}
}
}
}
return 0;
}
by DDD_et @ 2024-09-27 19:00:30
@limingyue
注意is函数里面,i 要从 2 开始
by limingyue @ 2024-09-28 18:11:20
@DDD_et
哦!
(其实我知道,但写错了,呜呜)
嘿嘿
by limingyue @ 2024-09-28 18:12:17
@XiaoHongChong
太感谢了
嘻嘻(开心)