黎明时空几何 @ 2016-08-25 10:16:03
var
n,i,j:longint;
function zs(ff:longint):boolean;
var
ii:longint;
br:boolean;
begin
br:=true;
for ii:=2 to round(sqrt(ff)) do
if ff mod ii=0 then br:=false;
zs:=br;
end;
begin
readln(n);
for i:=2 to n do
for j:=2 to n-i do
if (zs(i)=true) and (zs(j)=true) and (zs(n-i-j)=true) then begin
write(i,' ',j,' ',n-i-j);
halt;
end;
end.
by 黎明时空几何 @ 2016-08-25 10:18:05
1 6 7 9 是错的。
by Hany01 @ 2016-08-25 14:06:36
n-i-j有可能等于1啊,那么判断就会出错啊
by paul120090105 @ 2016-11-03 18:41:37
var
i,j,n:longint;
function zs(n:int64):boolean;
var
i:longint;
begin
zs:=true;
if n<=1 then exit(false);
for i:=2 to trunc(sqrt(n)) do
if n mod i=0 then exit(false);
end;
begin
readln(n);
for i:=2 to n do
for j:=2 to n-1 do
if zs(i) and zs(j) and zs(n-i-j) then begin
writeln(i,' ',j,' ',n-i-j);
exit;
end;
end.
//只要在函数里加一个判断句就行了