#include <bits/stdc++.h>
using namespace std;
const char *word[] = {"NO\n", "YES\n"};
int main() {
  int w, m;
  scanf("%d%d", &w, &m);
  bool ans = true;
  if (w > 2)
    while (m) {
      int d = m % w;
      if (d != 0 and d != 1 and d != w - 1) ans = false;
      m /= w;
      if (d == w - 1) m++;
    }
  printf(word[ans]);
}
