#include <bits/stdc++.h>
using namespace std;
int w, m;
vector<int> convertBase(int m, int w) {
  vector<int> digits;
  while (m > 0) {
    digits.push_back(m % w);
    m /= w;
  }
  return digits;
}
void display(vector<int> x) {
  for (int i = 0; i < x.size(); i++) {
    cout << x[i];
  }
  cout << '\n';
}
int main() {
  ifstream fin("arbsat2.in");
  ofstream fout("arbsat2.out");
  cin >> w >> m;
  vector<int> x;
  int aux = 1;
  x = convertBase(m, w);
  int i, n = x.size();
  for (i = 0; i <= n - 2 && aux == 1; i++) {
    if (x[i] == 0 || x[i] == 1) {
      continue;
    }
    if (2 <= x[i] && x[i] <= w - 2) {
      aux = 0;
    }
    if (x[i] >= w - 1) {
      x[i + 1]++;
    }
  }
  if (2 <= x[n - 1] && x[n - 1] <= w - 2) {
    aux = 0;
  }
  if (aux == 1) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  fin.close();
  fout.close();
  return 0;
}
