#include <bits/stdc++.h>
using namespace std;
vector<long long int> vec;
int main() {
  long long int w, m;
  cin >> w >> m;
  long long int r;
  while (m != 0) {
    r = m % w;
    if (r > w / 2) {
      m++;
      r = r - w;
    }
    vec.push_back(r);
    m = m / w;
  }
  for (int i = 0; i < vec.size(); i++) {
    if (vec[i] != 0 && vec[i] != 1 && vec[i] != -1) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  vec.clear();
  return 0;
}
