#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  int ss = ((int)(v).size());
  for (int(i) = 0; (i) < (ss); ++(i)) out << v[i] << " ";
  return out;
}
template <typename T, typename TT>
ostream& operator<<(ostream& out, const pair<T, TT>& p) {
  out << p.first << " " << p.second;
  return out;
}
template <typename T, typename TT>
istream& operator>>(istream& in, pair<T, TT>& s) {
  in >> s.first >> s.second;
  return in;
}
template <typename T>
bitset<sizeof(T) * 8> BIN(T a) {
  return bitset<sizeof(T) * 8>(a);
}
int main() {
  int w, m;
  cin >> w >> m;
  int arr[50];
  int n = 0;
  while (m) {
    arr[n] = m % w;
    m /= w;
    n++;
  }
  int good = 1;
  for (int(i) = 0; (i) < (n); ++(i)) {
    if (arr[i] != 0 && arr[i] != 1 && arr[i] != w - 1 && arr[i] != w) {
      good = 0;
      break;
    } else {
      if (arr[i] == w - 1 || arr[i] == w) {
        arr[i + 1]++;
      }
    }
  }
  cout << (good ? "YES" : "NO") << endl;
  return 0;
}
