program Main;
uses
SysUtils;
var
n, temp, chuSo, maxChuSo, soMax: Integer;
soUoc, soChuSo: Integer;
function DemUoc(num: Integer): Integer;
var
i: Integer;
begin
DemUoc := 0;
for i := 1 to num do
begin
if num mod i = 0 then
begin
Inc(DemUoc);
writeln('Uoc: ', i);
end;
end;
end;
function TimChuSoMax(num: Integer): Integer;
var
maxChuSo: Integer;
begin
maxChuSo := 0;
while num > 0 do
begin
chuSo := num mod 10;
if chuSo > maxChuSo then
maxChuSo := chuSo;
num := num div 10;
end;
TimChuSoMax := maxChuSo;
end;
function SapXepSoMax(num: Integer; chuSo: Integer): Integer;
var
i, j, maxIndex: Integer;
mangSo: array[1..6] of Integer;
soMax: Integer;
begin
soMax := 0;
for i := 1 to chuSo do
begin
mangSo[i] := num mod 10;
num := num div 10;
end;
for i := 1 to chuSo - 1 do
begin
maxIndex := i;
for j := i + 1 to chuSo do
begin
if mangSo[j] > mangSo[maxIndex] then
maxIndex := j;
end;
temp := mangSo[i];
mangSo[i] := mangSo[maxIndex];
mangSo[maxIndex] := temp;
end;
for i := 1 to chuSo do
soMax := soMax * 10 + mangSo[i];
SapXepSoMax := soMax;
end;
begin
repeat
writeln('Nhap so nguyen n (2 < k < 7): ');
readln(n);
until (n >= 10) and (n < 1000000);
if n = 0 then
begin
writeln('0 co 0 uoc');
writeln('0 co 1 chu so');
writeln('Chu so lon nhat cua 0 la 0');
writeln('So lon nhat la: 0');
end
else
begin
soUoc := DemUoc(n);
writeln(n, ' co ', soUoc, ' uoc');
soChuSo := Length(IntToStr(n));
writeln(n, ' co ', soChuSo, ' chu so');
maxChuSo := TimChuSoMax(n);
writeln('Chu so lon nhat cua ', n, ' la ', maxChuSo);
soMax := SapXepSoMax(n, soChuSo);
writeln('So lon nhat la: ', soMax);
end;
end.