#include <iostream>
#include <math.h>
#include <string>

using namespace std;
int f[25];
bool ok = 1;

int main()
{
	int n, m,maxim=0;
	cin >> n >> m;
	while (n)
	{
		f[n % m]++;
		n /= m;
	}
	for(int i=0;i<16;i++)
		if (f[i] != 1 && f[i])
		{
			cout << "NO";
			exit(0);
		}
	cout << "YES";
}

