#include <bits/stdc++.h>
using namespace std;
vector<long long> vec;
long long n, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cin >> n >> m;
  while (m) {
    vec.push_back(m % n);
    m /= n;
  }
  for (int i = 0; i < vec.size(); i++) {
    if (vec[i] <= 1) continue;
    if (vec[i] == n - 1) {
      vec[i] = 0;
      if (i + 1 == vec.size()) {
        vec.push_back(1);
      } else {
        vec[i + 1]++;
      }
      continue;
    }
    if (vec[i] == n) {
      vec[i] = 0;
      if (i + 1 == vec.size()) {
        vec.push_back(1);
      } else {
        vec[i + 1]++;
      }
      continue;
    }
    cout << "NO" << endl;
    exit(0);
  }
  if (vec.back() <= 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
