program BaiTap;
uses crt;
var
N: string;
i, j, product, diff, minNum: integer;
prime: array[0..9] of boolean;
function isPrime(x: integer): boolean;
var
i: integer;
begin
if x < 2 then
exit(false);
for i := 2 to trunc(sqrt(x)) do
if x mod i = 0 then
exit(false);
exit(true);
end;
begin
clrscr;
write('Nhap so N = ');
readln(N);
product := 1;
for i := 1 to length(N) do
if (ord(N[i]) - ord('0')) mod 2 <> 0 then
product := product * (ord(N[i]) - ord('0'));
writeln('Tich cac so le co trong ', N, ' la: ', product);
for i := 0 to 9 do
prime[i] := isPrime(i);
write('Cac so nguyen to co trong ', N, ' la: ');
for i := 1 to length(N) do
if prime[ord(N[i]) - ord('0')] then
write(ord(N[i]) - ord('0'), ' ');
writeln;
for i := 1 to length(N) - 1 do
for j := i + 1 to length(N) do
if N[i] > N[j] then
begin
N[i] := chr(ord(N[i]) xor ord(N[j]));
N[j] := chr(ord(N[i]) xor ord(N[j]));
N[i] := chr(ord(N[i]) xor ord(N[j]));
end;
val(N, minNum, i);
diff := strToInt(N) - minNum;
writeln('So nho nhat la: ', minNum);
writeln(strToInt(N), '-', minNum, '=', diff);
end.