#include <bits/stdc++.h>
using namespace std;
long long int mn = 1e18;
long long int mx = -1e18;
const long long int mv = 1000005;
const double pi = 3.141592653589793238462643;
long long int w, m, c;
vector<long long int> a;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cin >> w >> m;
  long long int op = 1;
  while (m) {
    a.push_back(m % w);
    m /= w;
  }
  int ch = 1;
  for (int i = 0; i < (int)(a.size()); ++i) {
    if (a[i] != 0 && a[i] != 1 && a[i] != w && a[i] != w - 1) {
      ch = 0;
    }
    if (a[i] == w - 1 || a[i] == w) {
      if (i < (int)(a.size()) - 1) {
        a[i + 1]++;
      }
    }
  }
  if (ch) {
    cout << "YES";
    return 0;
  }
  cout << "NO";
}
