#include <bits/stdc++.h>
using namespace std;
const int L = 1000 + 10;
int b[L];
int w, m, l = 0;
int main() {
  cin >> w >> m;
  if (w > 3)
    while (m) {
      int q = m % w;
      m /= w;
      if (q > 1 && q < w - 1) {
        cout << "NO" << endl;
        return 0;
      }
      if (q == w - 1) m++;
    }
  cout << "YES" << endl;
  return 0;
}
