#include <bits/stdc++.h>
using namespace std;
vector<long long> p, a, b;
void calc(int s, int e, int sum, vector<long long> &v) {
  if (s == e) {
    v.push_back(sum);
    return;
  }
  calc(s + 1, e, sum, v);
  calc(s + 1, e, sum + p[s], v);
  calc(s + 1, e, sum - p[s], v);
}
int main() {
  int w, m;
  scanf("%d%d", &w, &m);
  if (w <= 3) {
    puts("YES");
    return 0;
  }
  p.push_back(1);
  for (long long i = w; i <= 10000000000ll; i *= (long long)w) p.push_back(i);
  int n = p.size();
  calc(0, n / 2, 0, a);
  calc(n / 2, n, 0, b);
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  a.resize(unique(a.begin(), a.end()) - a.begin());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  for (int i = 0; i < (int)a.size(); ++i) {
    if (binary_search(b.begin(), b.end(), -1 * (m + a[i]))) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}
