#include <bits/stdc++.h>
using namespace std;
int main() {
  long long w, m;
  cin >> w >> m;
  vector<int> a;
  long long z = m;
  while (z) {
    a.push_back(z % w);
    z /= w;
  }
  a.push_back(0);
  int flag = 1;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] == w || a[i] == w - 1) {
      a[i] -= w;
      a[i + 1] += 1;
    }
  }
  for (int i = 0; i < a.size(); i++)
    if (a[i] != 0 && a[i] != 1 && a[i] != -1) {
      flag = 0;
      break;
    }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
