

Input

The input contains two integers N, M (1 ≤ N ≤ 1024, 2 ≤ M ≤ 16), separated by a single space.

Output

Output "YES" or "NO".

Examples

Input


2 3


Output


YES


Input


3 2


Output


NO


Input


33 16


Output


YES


Input


26 5


Output


NO
read = lambda: map(int, input().split(" "))
from math import log
n,m=read()
maxp=int(log(n)/log(m))
arr=[0]*(maxp+1)
i=maxp
while n!=0:
    a=m**i

    arr[maxp-i]=int(n/a)
    n=n%a
    i-=1
ans="NO"
k=set(arr)
l=len(k)
if l==maxp+1:
    ans="YES"
print(ans)
