#include <bits/stdc++.h>
using namespace std;
long long s, i, j, m, k, x, y, l, n, a[2002], w, p;
bool ma;
int main() {
  cin >> w >> m;
  if (w == 2) {
    cout << "YES";
    return 0;
  }
  if (m % w != (w - 1) && m % w != 0 && m % w != 1) {
    cout << "NO" << endl;
    return 0;
  }
  k = w;
  s = 1;
  for (i = 1; i <= 100; i++) {
    s += k;
    if (s > 1000000000) {
      ma = true;
      break;
    }
    if (k > 1000000000 / w - 1) {
      ma = true;
      break;
    } else
      k = k * w;
  }
  if (!ma && s < m) {
    cout << "NO" << endl;
    return 0;
  }
  while (1) {
    if (m % w != (w - 1) && m % w != 0 && m % w != 1) {
      cout << "NO" << endl;
      return 0;
    }
    if (1 == m || w == m || m == w - 1) {
      cout << "YES" << endl;
      return 0;
    }
    if (m % w == 0 || m % w == 1)
      m = m / w;
    else
      m = m / w + 1;
  }
  return 0;
}
