

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

def isxenodrome(num,base):
	digset = set()
	potbase = base
	
	while potbase <= num:
		dig = num%potbase
		num -= dig
		dig /= potbase/base
		dig = int(dig)
		# print(dig)
		if dig in digset:
			return False
		digset.add(dig)
		potbase *= base
	dig = num%potbase
	num -= dig
	dig /= potbase/base
	dig = int(dig)
	# print(dig)
	if dig in digset:
		return False
	potbase *= base
	
	return True
	

num, base = map(int, input().split())

val = isxenodrome(num,base)
if val:
	print('YES')		
else:
	print('NO')	
