#include <bits/stdc++.h>
using namespace std;
int main() {
  int w, m;
  cin >> w >> m;
  vector<int> p(1000, 0);
  int n = 0;
  while (m > 0) {
    p[n] = m % w;
    m /= w;
    n++;
  }
  bool boo = true;
  for (int i = 0; i <= 120; i++) {
    if (p[i] > 1) {
      p[i] -= w;
      p[i + 1]++;
    }
    if (p[i] < -1) boo = false;
  }
  if (boo)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
