#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
int on(int n, int pos) { return n = n | (1 << pos); }
int dx[] = {0, 0, 1, -1};
int dy[] = {-1, 1, 0, 0};
vector<long long int> vc, my[4];
double big = 100000000000;
map<long long int, int> name;
void backtrack(int pos, long long int val, int lim, int id) {
  if (pos >= lim) {
    my[id].push_back(val);
    return;
  }
  backtrack(pos + 1, val, lim, id);
  backtrack(pos + 1, val + vc[pos], lim, id);
  backtrack(pos + 1, val - vc[pos], lim, id);
}
int main() {
  int i, j, k, l, n;
  long long int m, w;
  cin >> w >> m;
  if (w == 2) {
    printf("YES\n");
    return 0;
  }
  long long int mul = 1;
  double dmul = 1;
  while (1) {
    if (dmul > big) break;
    vc.push_back(mul);
    mul = mul * w;
    dmul = dmul * w;
  }
  backtrack(0, 0, vc.size() / 2, 0);
  backtrack((vc.size() / 2), 0, vc.size(), 1);
  for (int i = 0; i < my[0].size(); i++) name[my[0][i]] = 1;
  for (int i = 0; i < my[1].size(); i++) {
    long long int p = m - my[1][i];
    if (name.find(p) != name.end()) {
      printf("YES\n");
      return 0;
    }
  }
  printf("NO\n");
}
