uses crt;
var d:array[1..100]of byte;
n,i,j,k:integer;
begin
clrscr;
write('Nhap n='); readln(n);
repeat
write('Nhap he dem can doi:'); readln(k);
until (k=2) or (k=8) or (k=16);
i:=1;
repeat
d[i]:=n mod k;
n:=n div k;
i:=i+1;
until n=0;
writeln('So he ',k,' la: ');
for j:=i-1 downto 1 do
begin
case d[j] of
0..9:write(d[j]);
10..16:write(chr(d[j]+55));
end;
end;
readln;
end.