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