#include <bits/stdc++.h>
using namespace std;
map<int, bool> M;
int a[] = {-1, 0, 1};
bool solve(int m, int w) {
  if (w == 2 || w == 3 || m == 1) return true;
  if (M.find(m) != M.end()) return M[m];
  for (int i = 0; i < 3; i++) {
    m += a[i];
    if (m % w == 0 && solve(m / w, w)) {
      m -= a[i];
      return (M[m] = true);
    } else
      m -= a[i];
  }
  return (M[m] = false);
}
int main() {
  int w, m, n, i, j;
  scanf("%d%d", &w, &m);
  if (solve(m, w))
    printf("YES");
  else
    printf("NO");
  return 0;
}
