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