import sys
if __name__=='__main__':
n = int(sys.stdin.readline().strip())
for i in range(n):
line = sys.stdin.readline().strip()
n, k = list(map(int, line.split()))
tmp = []
t = 0
while(n!=0):
t = n % k
tmp.append(t)
n = n // k
re = 0
tmp = tmp[::-1]
for index, j in enumerate(tmp):
re += (j * (k**index))
print(re)
if __name__=='__main__':
n = int(input().strip())
for i in range(n):
h_min = 999999
v_min = 999999
h_index, v_index = 0, 0
n, m = list(map(int, input().strip().split()))
mat = [[0 for _ in range(m)]for _ in range(n)]
for row in range(n):
for col in range(m):
mat[row][col] = row * m + col +1
for h in range(n):
top, bottom = 0, 0
for i in range(h):
top += sum([mat[i][j] for j in range(m)])
for i in range(h, n):
bottom += sum([mat[i][j] for j in range(m)])
if abs(top - bottom) < h_min:
h_min = abs(top - bottom)
h_index = h
for v in range(m):
left, right=0,0
for i in range(v):
left += sum([mat[j][i] for j in range(n)])
for i in range(v, m):
right += sum([mat[j][i] for j in range(n)])
if abs(left - right) < v_min:
v_min = abs(left - right)
v_index = v
print(('V', v_index+1) if v_min < h_min else ('H', h_index+1))
第一题给一个十进制数,转换成k进制,然后把转换结果倒序,然后把倒序后的k进制数重新转换为十进制示例1:输入: 8 2输出:1说明:8的二进制表示为:1000,倒序后为0001,再转换为十进制为1示例2:输入为: 11 3输出为:19说明:11的3进制表示为201, 倒序后为102,再转换为十进制为19import sysif __name__=='__main__': n = int(sys.stdin.readline().strip()) for i