#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, rem;
  cin >> n >> k;
  long long int ans = 0;
  int i = 0;
  while (k > 0) {
    rem = k % n;
    k /= n;
    if ((rem != 0) && (rem != 1)) {
      if (n - rem > 1) {
        cout << "NO";
        exit(0);
      } else {
        k++;
      }
    }
  }
  if (rem > 1) {
    cout << "NO";
  } else {
    cout << "YES";
  }
  return 0;
}
