#include <bits/stdc++.h>
int main() {
  int w, m;
  scanf("%d%d", &w, &m);
  int a[50] = {};
  for (int i = 0; m > 0; ++i, m /= w) a[i] = m % w;
  for (int i = 0; i < 49; ++i) {
    if (a[i] == w) {
      a[i] = 0;
      a[i + 1]++;
    }
    if (a[i] > 1 and a[i] != w - 1) {
      puts("NO");
      return 0;
    }
    if (a[i] == w - 1) a[i + 1]++;
  }
  puts("YES");
}
