#include <bits/stdc++.h>
using namespace std;
int main() {
  long long w, m;
  while (cin >> w >> m) {
    long long sum = 0;
    long long t = 1;
    vector<long long> scale;
    while (t < m) {
      scale.push_back(t);
      sum += t;
      t *= w;
    }
    scale.push_back(t);
    sum += t;
    long long x = sum - m;
    for (int i = scale.size() - 1; i >= 0 && x != 0; i--) {
      if (x >= scale[i] * 2) {
        x -= scale[i] * 2;
      } else if (x >= scale[i]) {
        x -= scale[i];
      }
    }
    if (x == 0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
