Her_Lingxiao @ 2020-02-06 22:58:44
我这个为什么没有输出???
我觉得是Windows的问题
#include <cstdio>
#include <cmath>
using namespace std;
int Judge(int o)
{
for(int i=1;i<=o;i++)
{
if(o%i==0)
return 1;
}
return 0;
}
int main()
{
int a,b,c;
int n;
int flag=0;
scanf("%d",&n);
for(a=2;a<=sqrt(n);a++)
{
if(Judge(a)==1)
continue;
for(b=2;b<=sqrt(n);b++)
{
if(Judge(b)==1)
break;
c=n-a-b;
if(Judge(c)==0)
{
if(flag==0)
{
flag++;
printf("%d %d %d\n",a,b,c);
break;
}
if(flag==1)
{
printf("%d %d %d",a,b,c);
goto end;
}
}
}
}
end:
return 0;
}
by answerend42 @ 2020-02-06 23:27:38
我觉得是你的Judge的问题,可以改成
#include <cstdio>
#include <cmath>
using namespace std;
int Judge(int o)
{
if(o<2)
return 1;
for(int i=2;i<=sqrt(o);i++)
{
if(o%i==0)
return 1;
}
return 0;
}
int main()
{
int a,b,c;
int n;
int flag=0;
scanf("%d",&n);
for(a=2;a<=n;a++)
{
for(b=2;b<=n;b++)
{
c=n-a-b;
if(Judge(a)+Judge(b)+Judge(c)!=0)
continue;
else
{
printf("%d %d %d",a,b,c);
return 0;
}
}
}
}
by answerend42 @ 2020-02-06 23:30:42
你的题意理解也错了,只用输出一组数据就可以了,可以考虑把
if(Judge(c)==0)
后的代码写成
printf("%d %d %d",a,b,c);
return 0;
by Her_Lingxiao @ 2020-02-07 10:49:42
谢谢