Skip to content

Instantly share code, notes, and snippets.

@knuu
Last active August 29, 2015 14:23
Show Gist options
  • Save knuu/63f967181f967641a881 to your computer and use it in GitHub Desktop.
Save knuu/63f967181f967641a881 to your computer and use it in GitHub Desktop.
Codeforces Round #307(Div. 2) - C. Vanya and Scales
def convert_base(num, base):
# numをbase進数に変換
converted = []
while num:
num, r = divmod(num, base)
converted.append(r)
return converted
def solve(w, m):
m_w = convert_base(m, w)
m_w += [0] * (101-len(m_w))
for i in range(101):
if m_w[i] == 0 or m_w[i] == 1:
continue
elif m_w[i] == w-1 or m_w[i] == w:
m_w[i+1] += 1 # 繰り上がりがおこる
else:
return False
return True
w, m = read_list(int)
print('YES' if solve(w, m) else 'NO')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment