Var n,i,j,resi,resj,flag:integer; begin flag:=0; i:=1; readln(n); while power(i,3)<n do begin j:=1; while power(j,3)+power(i,3)<=n do begin if power(j,3)+power(i,3)=n then begin flag:=1; resi:=i; resj:=j; break; end; inc(j); end; if flag=1 then break; inc(i); end; if flag=1 then writeln(resi,' ',resj,' ',resj,' ',resi) else writeln('impossible'); end.
Пример ввода: 1008 //2^3+10^3 Пример вывода: 2 10 10 2
Var a:array[1..3,1..3] of integer; t:array[0..2] of boolean; k:array[0..2] of integer; i,j:integer; res:boolean;
begin for i := 1 to 3 do for j := 1 to 3 do read(a[i,j]); for i := 0 to 2 do begin k[i] := 0; t[i] := false; end;
for i := 1 to 3 do for j := 1 to 3 do k[a[i,j]] := k[a[i,j]] + 1;
for i := 1 to 3 do begin if (a[i,1] = a[i,2]) and (a[i,2] = a[i,3]) then t[a[i,1]] := true; if (a[1,i] = a[2,i]) and (a[2,i] = a[3,i]) then t[a[1,i]] := true; end; if (a[1,1] = a[2,2]) and (a[2,2] = a[3,3]) then t[a[2,2]] := true; if (a[3,1] = a[2,2]) and (a[2,2] = a[1,3]) then t[a[2,2]] := true;
res := true;
if (k[1] - k[2] > 1) or (k[1] - k[2] < 0) then res := false;
if t[1] and ( t[2] or (k[1] = k[2]) ) then res := false;
if res then writeln('YES') else writeln('NO') end.
Var
n,i,j,resi,resj,flag:integer;
begin
flag:=0;
i:=1;
readln(n);
while power(i,3)<n do
begin
j:=1;
while power(j,3)+power(i,3)<=n do
begin
if power(j,3)+power(i,3)=n then
begin
flag:=1;
resi:=i;
resj:=j;
break;
end;
inc(j);
end;
if flag=1 then break;
inc(i);
end;
if flag=1 then writeln(resi,' ',resj,' ',resj,' ',resi) else writeln('impossible');
end.
Пример ввода:
1008 //2^3+10^3
Пример вывода:
2 10 10 2
a:array[1..3,1..3] of integer;
t:array[0..2] of boolean;
k:array[0..2] of integer;
i,j:integer;
res:boolean;
begin
for i := 1 to 3 do
for j := 1 to 3 do
read(a[i,j]);
for i := 0 to 2 do
begin
k[i] := 0;
t[i] := false;
end;
for i := 1 to 3 do
for j := 1 to 3 do
k[a[i,j]] := k[a[i,j]] + 1;
for i := 1 to 3 do
begin
if (a[i,1] = a[i,2]) and (a[i,2] = a[i,3]) then
t[a[i,1]] := true;
if (a[1,i] = a[2,i]) and (a[2,i] = a[3,i]) then
t[a[1,i]] := true;
end;
if (a[1,1] = a[2,2]) and (a[2,2] = a[3,3]) then
t[a[2,2]] := true;
if (a[3,1] = a[2,2]) and (a[2,2] = a[1,3]) then
t[a[2,2]] := true;
res := true;
if (k[1] - k[2] > 1) or (k[1] - k[2] < 0) then
res := false;
if t[1] and ( t[2] or (k[1] = k[2]) ) then
res := false;
if res then
writeln('YES')
else
writeln('NO')
end.