#include "bits/stdc++.h"

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  unordered_set<int> s;
  while (n) {
    if (!s.insert(n % m).second) {
      cout << "NO" << endl;
      return 0;
    }
    n /= m;
  }
  cout << "YES" << endl;
  return 0;
}
