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