#include <bits/stdc++.h>
using namespace std;
struct _ {
  _() { cin.sync_with_stdio(0), cin.tie(0); }
} _;
signed main() {
  long long m, M, f = 1;
  cin >> m >> M;
  while (M and f) {
    if (M % m < 2)
      M /= m;
    else if (M % m + 1 == m)
      M = M / m + 1;
    else
      f = 0;
  }
  f ? cout << "YES" : cout << "NO";
}
