#include <bits/stdc++.h>
int main(void) {
  int w, m;
  scanf("%d %d", &w, &m);
  while (m) {
    if (m % w == 1) --m;
    if (m % w == w - 1) ++m;
    if (m % w == 0)
      m /= w;
    else {
      printf("NO");
      return 0;
    }
  }
  printf("YES");
  return 0;
}
