#include <bits/stdc++.h>
using namespace std;
int main() {
  long long w, m, carry = 0, t;
  cin >> w >> m;
  while (m) {
    t = m % w;
    t += carry;
    carry = t / w;
    t %= w;
    if (t != 1 && t != 0 && t != w - 1) {
      cout << "NO";
      return 0;
    }
    if (t == w - 1) carry++;
    m /= w;
  }
  cout << "YES";
}
