#include <bits/stdc++.h>
int main() {
  int w, m;
  scanf("%d %d", &w, &m);
  int k = 0;
  int pos[40];
  while (m) {
    pos[k++] = m % w;
    m /= w;
  }
  pos[k] = 0;
  bool mak = false;
  for (int i = 0; i <= k; i++) {
    if (pos[i] == w || pos[i] == w - 1) {
      pos[i + 1]++;
      continue;
    }
    if (pos[i] >= 2) {
      mak = true;
      break;
    }
  }
  if (mak)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
