#include <bits/stdc++.h>
using namespace std;
int main() {
  int w, m;
  cin >> w >> m;
  string yy = "YES";
  string nn = "NO";
  if (w == 2 || m == 1) {
    cout << yy << endl;
    return 0;
  }
  while (m) {
    if (m % w == 0) {
      m /= w;
    } else {
      int r = m % w;
      if (r == 1) {
        m = (m - 1) / w;
      } else if (r == w - 1) {
        m = (m + 1) / w;
      } else {
        cout << nn << endl;
        return 0;
      }
    }
  }
  cout << yy << endl;
  return 0;
}
