#include <bits/stdc++.h>
using namespace std;
int main() {
  int w, m, k;
  bool f;
  cin >> w >> m;
  f = true;
  if (w > 3) {
    k = 0;
    while (m > 1 && f) {
      for (; m % w == 0; m /= w) {
        k++;
      }
      if ((m - 1) % w == 0) {
        m--;
      } else if ((m + 1) % w == 0) {
        m++;
      } else {
        f = false;
      }
    }
    f &= (k <= 100);
  }
  cout << (f ? "YES" : "NO");
  return 0;
}
