#include <bits/stdc++.h>
using namespace std;
long long notation[40], c;
int main() {
  long long w, n;
  cin >> w >> n;
  while (n) {
    notation[c++] = n % w;
    n /= w;
  }
  for (int i = 0; i != c; i++) {
    if (notation[i] != 1 && notation[i] != 0 && notation[i] != w - 1 &&
        notation[i] != w) {
      cout << "NO";
      return 0;
    } else {
      if (notation[i] == w - 1 || notation[i] == w) {
        notation[i + 1]++;
      }
    }
  }
  cout << "YES";
}
