#include <bits/stdc++.h>
int c[100];
int main() {
  int t, i, flag, p, r, w, m;
  scanf("%d%d", &w, &m);
  p = flag = 1;
  while (m) {
    r = m % w;
    c[++c[0]] = r;
    m = m / w;
  }
  t = 0;
  for (i = 1; i <= c[0]; ++i) {
    c[i] = c[i] + t;
    t = 0;
    if (c[i] == w) {
      c[i] = 0;
      t = 1;
      continue;
    }
    if (c[i] == 1 || c[i] == 0) continue;
    if (c[i] == w - 1) {
      t = 1;
      continue;
    }
    flag = 0;
  }
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
