#include <bits/stdc++.h>
using namespace std;
bool trySolve(long long w, long long m);
bool solve(long long w, long long m);
bool trySolve(long long w, long long m) {
  return m % w == 0 && solve(w, m / w);
}
bool solve(long long w, long long m) {
  if (w <= 3 || m == 1 || trySolve(w, m - 1) || trySolve(w, m) ||
      trySolve(w, m + 1)) {
    return true;
  }
  return false;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long w, m;
  cin >> w >> m;
  if (solve(w, m)) {
    cout << "YES"
         << "\n";
  } else {
    cout << "NO"
         << "\n";
  }
  return 0;
}
