#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, w;
  bool y = 1;
  cin >> w >> m;
  vector<int> digits;
  int temp = m;
  while (temp) {
    digits.push_back(temp % w);
    temp /= w;
  }
  for (auto i = 0; i < digits.size(); ++i) {
    if ((digits[i] == w || digits[i] == w - 1) && i != digits.size() - 1) {
      digits[i] -= w;
      digits[i + 1] += 1;
    } else if (digits[i] == w || digits[i] == w - 1) {
      digits[i] -= w;
      digits.push_back(1);
      break;
    } else if (digits[i] == 1 || digits[i] == 0) {
    } else {
      y = 0;
      break;
    }
  }
  if (y)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return EXIT_SUCCESS;
}
