#include <bits/stdc++.h>
using namespace std;
long long num[50];
int main() {
  long long w, m;
  cin >> w >> m;
  long long tp = m;
  int ct = 0;
  while (tp > 0) {
    num[ct] = tp % w;
    ct++;
    tp /= w;
  }
  int fl = 0;
  for (int i = 0; i < ct + 1; i++) {
    if (num[i] != 0 && num[i] != 1 && num[i] != w - 1) {
      fl = 1;
      break;
    } else if (num[i] == w - 1) {
      int j = i + 1;
      num[j]++;
      while (num[j] == w) {
        num[j] = 0;
        num[j + 1]++;
        j++;
      }
    }
  }
  if (fl == 1) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
  }
  return 0;
}
