#include <bits/stdc++.h>
using namespace std;
bool solve(int w, int m) {
  if (w <= 3 || m == 1) return true;
  if ((m % w == 0) && solve(w, m / w)) return true;
  if (((m - 1) % w == 0) && solve(w, (m - 1) / w)) return true;
  if (((m + 1) % w == 0) && solve(w, (m + 1) / w)) return true;
  return false;
}
int main() {
  int w, m;
  cin >> w >> m;
  if (solve(w, m))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
