#include <bits/stdc++.h>
using namespace std;
int main() {
  int w, m, a[32], c = 0, i;
  cin >> w >> m;
  while (m) {
    a[c++] = m % w;
    m /= w;
  }
  for (i = 0; i < c; ++i) {
    if (a[i] != 0 && a[i] != 1 && a[i] != w && a[i] != w - 1) {
      cout << "NO";
      exit(0);
    } else if (a[i] == w || a[i] == w - 1)
      a[i + 1]++;
  }
  cout << "YES";
  return 0;
}
