#include<bits/stdc++.h>
using namespace std;
int n, m;
map<int, int> mp;
int main() {
	cin >> n >> m;
	while(n) {
		if(mp[n % m])
			return 0 *puts("NO");
		mp[n % m] = 1;
		n /= m;
	}
	puts("YES");
}