Pascal
Modified: Wednesday, 22-12-2021 07:00 AM
TH1: Tách số thành tổng của 3 số phân biệt
TH2: Tách số thành tổng của 3 số nguyên tố x,y,z với x<=y<=z
TH1:
const out='Export';
var n:integer;
a,b,c:integer;
sa,sb,sc,s:ansistring;
f:text;
begin
write('Input a number in [6..1000] : ');
readln(n);
s:='';
for a:= 1 to n div 3 do
for b:= a+1 to n-(a+1) do
begin
c:=n-(a+b);
if c<>(a and b) then
if (a<b) and(b<c) then
begin
str(a,sa);
str(b,sb);
str(c,sc);
s:=s+sa+'-'+sb+'-'+sc+';'+#13+#10;
end;
end;
assign(f, out);
rewrite(f);
write(f,s);
close(f);
write('Finished! See the Result in ',out,' File.');
readln;
end.
TH2:
var n,i:integer;
a,b,c:integer;
function snt(x:integer):boolean;
var i: integer;
begin
if (x<2) then exit(false);
for i := 2 to round(sqrt(x)) do
if (x mod i = 0) then exit(false);
exit(true);
end;
begin
write('Input a number in [6..1000] : ');
readln(n);
i:=0;
for a:= 2 to n div 3 do
if snt(a) then
begin
for b:= a to n-a do
if snt(b) then
begin
c:=n-(a+b);
if c < b then break;
if snt(c) then
begin
inc(i);
writeln('bo so ',i:3,': ',a:3,'-',b:3,'-',c:3)
end;
end;
end;
readln;
end.