#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-6;
const int INF = (int)(INT_MAX - 100);
const long long mod = (int)(1e+9 + 7);
const int N = (int)(0);
int main() {
  int w, m;
  cin >> w >> m;
  vector<int> coef;
  while (m) {
    coef.push_back(m % w);
    m /= w;
  }
  for (int i = 0; i < int(coef.size()); i++) {
    if (coef[i] <= 1) continue;
    if (coef[i] < w - 1) return cout << "NO", 0;
    ;
    coef[i + 1]++;
  }
  cout << "YES";
  return 0;
}
