#include <bits/stdc++.h>
using namespace std;
int main() {
  long long w, m;
  cin >> w >> m;
  vector<int> a;
  while (m) {
    a.push_back(m % w);
    m /= w;
  }
  a.push_back(0);
  a.push_back(0);
  for (int i = 0; i < ((int)a.size()) - 1; i++) {
    if (a[i] != 0 && a[i] != 1 && a[i] != w - 1 && a[i] != w) {
      cout << "NO" << '\n';
      exit(0);
    } else if (a[i] == w - 1 || a[i] == w) {
      a[i + 1]++;
    }
  }
  cout << "YES" << '\n';
  return 0;
}
