#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
signed main() {
  long long w, m;
  cin >> w >> m;
  long long t = m;
  while (t) {
    v.push_back(t % w);
    t /= w;
  }
  long long F = 1;
  v.push_back(0);
  v.push_back(0);
  for (long long i = 0; i < v.size(); i++) {
    if (v[i] == 1 || v[i] == 0)
      continue;
    else {
      v[i] = v[i] + 1;
      v[i + 1] = v[i + 1] + v[i] / w;
      v[i] = v[i] % w;
      if (v[i] <= 1)
        continue;
      else {
        F = 0;
        break;
      }
    }
  }
  if (F)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
