#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

int main() {
	
	int n, m;
	cin >> n >> m;
	set <int> elements;
	while (n) {
		if (!elements.insert(n % m).second) {
			cout << "NO\n";
			return 0;
		} n /= m;
	} cout << "YES\n";
	
	return 0;
	
/*
2 3
*/
}