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