#include <bits/stdc++.h>
using namespace std;
long long w, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> w >> m;
  int mem = m;
  if (w <= 3) {
    cout << "YES" << endl;
    exit(0);
  }
  vector<int> vec;
  while (m > 0) {
    vec.push_back(m % w);
    m /= w;
  }
  vec.push_back(0);
  int sz = vec.size();
  for (int i = 0; i < (1 << sz); i++) {
    long long new_num = 0;
    long long t = i;
    long long cur = 1;
    while (t > 0) {
      new_num += cur * (t % 2);
      t /= 2;
      cur *= w;
    }
    long long res = mem + new_num;
    bool ok = true;
    while (res > 0) {
      if (res % w > 1) {
        ok = false;
        break;
      }
      res /= w;
    }
    if (ok) {
      cout << "YES" << endl;
      exit(0);
    }
  }
  cout << "NO" << endl;
  return 0;
}
