#include <bits/stdc++.h>
using namespace std;
int n, w, m, a[32];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> w >> m;
  n = 0;
  while (m) {
    a[n++] = m % w;
    m /= w;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] <= 1) continue;
    if (a[i] == w - 1 || a[i] == w)
      a[i + 1]++;
    else {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
  return 0;
}
