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