#include <bits/stdc++.h>
using namespace std;
bool ok(long long w, long long m) {
  int k = 0;
  long long tw = 1;
  while (tw * w <= m) {
    tw *= w;
    k++;
  }
  int cnt[k + 2];
  for (int i = 0; i < k + 2; ++i) cnt[i] = 0;
  for (int i = k; i >= 0; --i) {
    tw = 1;
    for (int j = 0; j < i; ++j) tw *= w;
    cnt[i] = m / tw;
    m %= tw;
  }
  for (int i = 0; i <= k; ++i) {
    if (cnt[i] == w) {
      cnt[i + 1]++;
      continue;
    }
    if (cnt[i] == 0 || cnt[i] == 1) continue;
    if (cnt[i] + 1 < w) return false;
    cnt[i + 1]++;
  }
  return true;
}
int main() {
  long long w, m;
  while (cin >> w >> m) {
    if (ok(w, m))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
