def change(m,n): a = '' while m > 0: x = m % n a = chr(65 + x % 10) + a if x >= 10 else str(x) + a m //= n return a
MN = list(map(int, input().strip().split()))
nli = []
m = MN[0]
if m<0:
sign = -1
m = -m
else:
sign = 1
n = MN[1]
while m>=n:
nli.append(m%n)
m = m//n
if m!=0:
nli.append(m)
nli = nli[::-1]
if sign==-1:
s = "-"
else:
s = ""
for n in nli:
if n<=9:
s += str(n)
else:
s += chr(ord('A')+(n-10))
print(s)
# python3
def digit2N(digit, N):
pos_flag = True if digit > 0 else False
digit = abs(digit)
adict = '0123456789ABCDEF'
ret = ''
while digit:
ret = adict[digit % N] + ret
digit = digit // N
return ret if pos_flag else ('-'+ret)
input_num, N = map(int, input().split(' '))
ret = digit2N(input_num, N)
print(ret)
def baseN(m, n): if m < 0: m = -m flag = True else: flag = False ans = '' while m > 0: each = divmod(m, n)[1] if each >= 10: ans += chr(65 + each - 10) else: ans += str(each) m //= n return '-'+ans[::-1] if flag else ans[::-1] m, n = map(int, input().split()) print(baseN(m, n))
import sys a = list(map(int,sys.stdin.readline().split())) b = [] if a[0]>0: while a[0]/a[1] : b.append(a[0]%a[1]) a[0] = (int(a[0]/a[1])) c = b[::-1] res = '' for i in range(len(c)): if c[i]==10: c[i] = 'A' elif c[i] ==11: c[i] = 'B' elif c[i] ==12: c[i] = 'C' elif c[i] ==13: c[i] = 'D' elif c[i] ==14: c[i] = 'E' elif c[i] ==15: c[i] = 'F' res = res +str(c[i]) print(res) else: a[0] = -a[0] while a[0]/a[1] : b.append(a[0]%a[1]) a[0] = (int(a[0]/a[1])) c = b[::-1] res = '' for i in range(len(c)): if c[i]==10: c[i] = 'A' elif c[i] ==11: c[i] = 'B' elif c[i] ==12: c[i] = 'C' elif c[i] ==13: c[i] = 'D' elif c[i] ==14: c[i] = 'E' elif c[i] ==15: c[i] = 'F' res = res +str(c[i]) print('-'+res)
import sys
M,N=list(map(int,sys.stdin.readline().strip().split()))
mydict={10:'A',11:'B',12:'C',13:'D',14:'E',15:'F'}
ans=[]
flag=0#负数标志
if M<0:#M为负数时,flag置1,并将M变为正数
flag=1
M=-M
while M>0:
res=M%N
M=M//N
if res>=10:#余数大于等于10时,映射为对应的字母
ans.append(mydict[res])
else:
ans.append(str(res))
ans.reverse()#余数倒序排列
print('-'*flag+''.join(ans))#负数时flag为1,加上负号
小心负数的坑就是了!!!
N,q = map(int,input().split())
dict_x = {10:'A',11:'B',12:'C',13:'D',14:'E',15:'F'}
ans = []
neg = False
if N<0:
neg=True
N = -N
while N>=q:
ans.append(N%q)
N = N//q
ans.append(N)
ans = [dict_x[x] if x > 9 else x for x in ans]
out = ''.join(list(map(str,ans))[::-1])
if neg==True:
out = '-' + out
print(out)
def baseN(num, b):
res = ""
if num > 0:
while num:
res = "0123456789ABCDEFGHIGKLMNOPQRSTUVWXYZ"[num % b] + res
num = num // b
return res
else:
num = -num
while num:
res = "0123456789ABCDEFGHIGKLMNOPQRSTUVWXYZ"[num % b] + res
num = num // b
return "-" + res
a, b = map(int, input().split())
print(baseN(a, b))
num =raw_input("")
M=int(num.split(" ")[0])
N=int(num.split(" ")[1])
arr=['A','B','C','D','E','F']
flag=True
if M<0:
flag=False
M=-M
snum=[]
while M!=0:
temp=M%N
M=M/N
if temp>9:
snum.append(arr[temp-10])
else:
snum.append(temp)
str1=''
snum=list(reversed(snum))
for i in xrange(len(snum)):
str1=str1+str(snum[i])
if flag==False:
print '-'+str1
else:
print str1
"""存在bug,但是牛客测试平台还是过了,很low很初级的思路"""
mn = map(int,raw_input("").split(" "))
m = mn[0]
n = mn[1]
tm = 0
if m<0:
tm = m*(-1)
else:
tm = m
string = ""
while True:
if tm/n>=1:
ys = tm%n
tm = tm/n
if ys>9:
if ys==10:
temp = "A"
elif ys==11:
temp = "B"
elif ys==12:
temp = "C"
elif ys==13:
temp = "D"
elif ys==14:
temp = "E"
elif ys==15:
temp = "F"
else:
temp = str(ys)
string = string+temp
else:
break
string = string + str(tm)
if m>0:
print string[::-1]
else:
print "-"+string[::-1]