题目链接:https://www.luogu.org/problem/P1579
代码:
#include <bits/stdc++.h>
using namespace std;
int x,i;
int y(int x){ //判断是否是素数;
for(i=2;i<=sqrt(x);i++){
if(x%i==0){
return 1;
}
}
return 0;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,k,j,t=0,p;
cin>>n;
if(y(n-4)==0){ //2是最小是质数,如果该数可以表示成2,2,n即为最小解;
cout<<"2 "<<"2 "<<n-4<<endl;
}else{
for(k=3;k<n-4;k+=2){ //偶数一定不是素数;
for(j=k;j<n-4;j+=2){
p = n-j-k;
if(y(k)+y(j)+y(p)==0){
cout<<k<<" "<<j<<" "<<p<<endl;
return 0;
}
}
}
}
}
原文:https://www.cnblogs.com/zz9100/p/11255492.html