#include <bits/stdc++.h>
using namespace std;
bool go(int, int);
bool solve(int w, int m) {
  return w == 2 || w == 3 || m == 1 || go(w, m - 1) || go(w, m) || go(w, m + 1);
}
bool go(int w, int m) { return m % w == 0 && solve(w, m / w); }
int main() {
  int w, m;
  cin >> w >> m;
  if (solve(w, m))
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
