#include <bits/stdc++.h>
using namespace std;
int wi[111];
int main() {
  int w, m;
  scanf("%d%d", &w, &m);
  for (int i = 0; m; ++i) {
    wi[i] = m % w;
    m /= w;
  }
  bool flag = 1;
  for (int i = 0; i <= 100; ++i) {
    if (wi[i] >= w) {
      int t = wi[i];
      wi[i] = w % t;
      wi[i + 1] += w / t;
    }
    if (wi[i] != 0 && wi[i] != 1 && wi[i] != w - 1) {
      flag = 0;
      break;
    }
    if (wi[i] == w - 1) {
      ++wi[i + 1];
    }
  }
  if (flag)
    puts("YES");
  else
    puts("NO");
  return 0;
}
