yuhui_2000_2008 @ 2019-04-14 15:03:46
using namespace std;
int zs(int x)//质数返回1,和数返回0
{
int flag=1;
for(int i=2;i<=sqrt(x);i++)
if(x%i==0) {flag=0;break;}
if(flag==0) return 0;
else return 1;
}
int main()
{
int n,i,j,num=1;
cin>>n;
for(i=2;i<n;i++)
{
for(j=2;j<n;j++)
{
while(zs(i)&&zs(j)&&zs(n-i-j)&&num<2)
{
cout<<i<<" "<<j<<" "<<n-i-j;
num++;
}
}
}
return 0;
}
by yuhui_2000_2008 @ 2019-04-14 15:12:32
using namespace std;
int zs(int x)//质数返回1,和数返回0
{
int flag=1;
for(int i=2;i<=sqrt(x);i++)
if(x%i==0) {flag=0;break;}
if(flag==0) return 0;
else return 1;
}
int main()
{
int n,i,j,num=1;
cin>>n;
for(i=2;i<n/2;i++)
{
for(j=2;j<n/2;j++)
{
if(zs(i)&&zs(j)&&zs(n-i-j))
{
cout<<i<<" "<<j<<" "<<n-i-j<<" "<<n<<endl;
break;
}
}
}
return 0;
}
这个程序的break不起作用,跪求大神给指点一二
by pmt2018 @ 2019-04-14 15:13:27
希望更丰富的展现?使用Markdown
by Yoo_ @ 2019-04-14 15:34:48
楼主代码
#include <iostream>
#include <cmath>
using namespace std;
int zs(int x) {
int flag=1;
for(int i=2; i<=sqrt(x); i++) if(x%i==0) {
flag=0;
break;
}
if(flag==0) return 0;
else return 1;
}
int main() {
int n,i,j,num=1;
cin>>n;
for(i=2; i<n/2; i++) {
for(j=2; j<n/2; j++) {
if(zs(i)&&zs(j)&&zs(n-i-j)) {
cout<<i<<" "<<j<<" "<<n-i-j<<" "<<n<<endl;
break;
}
}
}
return 0;
}
by yuhui_2000_2008 @ 2019-04-14 19:01:32
问题已经解决,源程序超时