#include <bits/stdc++.h>
using namespace std;
const long long inf = 5e9;
long long w[20], s[20], m;
bool solve(int bm) {
  long long l = 0, r = m;
  for (int i = 0; i < 14; ++i) {
    if (bm % 3 == 0)
      l += w[i];
    else if (bm % 3 == 1)
      r += w[i];
    bm /= 3;
  }
  return l == r;
}
void special4() {
  while (m > 0) {
    if (m % 4 == 2) {
      cout << "NO\n";
      exit(0);
    }
    if (m % 4 == 3) {
      m += 4;
    }
    m /= 4;
  }
  cout << "YES\n";
}
int main() {
  w[0] = 1;
  cin >> w[1] >> m;
  if (w[1] <= 3) {
    cout << "YES\n";
    return 0;
  }
  for (int i = 2; i < 20; ++i) {
    w[i] = w[i - 1] * w[1];
    if (w[i] > inf) w[i] = 0;
  }
  if (w[1] == 4) {
    special4();
    return 0;
  }
  for (int bm = 0; bm < (int)5e6; ++bm) {
    if (solve(bm)) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
};
