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