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