Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.

Vanya wants to know how many digits he will have to write down as he labels the books.
The first line contains integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">9</sup>) — the number of books in the library.
l = set()
r = set()

def genl(i, s):
    if (i == 13):
        l.add(s)
        return

    genl(i + 1, s - a[i])
    genl(i + 1, s)
    genl(i + 1, s + a[i])


def genr(i, s):
    if (i == 13):
        r.add(s)
        return

    genr(i + 1, s - a[i])
    genr(i + 1, s)
    genr(i + 1, s + a[i])


w, n = map(int, input().split())

if w == 2:
    print("YES")
    exit(0)

a = []
for i in range(13):
    a.append(w ** i)

b = []
for i in range(13):
    b.append(w ** (13 + i))

genl(0, 0)
genr(0, 0)

for e in l:
    if (n - e) in r:
        print("YES")
        exit(0)

print("NO")