#include <bits/stdc++.h>
using namespace std;
inline bool ascending(int i, int j) { return (i < j); }
inline bool descending(int i, int j) { return (i > j); }
const long long MAXW = 1000 * 1000 * 1000 * 10;
const int MAXN = 100;
long long arr[MAXN], dif[MAXN];
bool flag[MAXN];
long long w, m, idx;
bool rec(long long m) {
  if (m == 0) return true;
  int pos = 0;
  while (m >= dif[pos] & pos < idx) pos++;
  if (pos) pos--;
  if (flag[pos])
    return false;
  else {
    flag[pos] = true;
    return rec(abs(arr[pos] - m));
  }
};
int main() {
  cin >> w >> m;
  if (w == 2) {
    cout << "YES" << endl;
    return 0;
  }
  long long tmp = 1;
  long long i = 0;
  for (i = 0; i < 100; i++) {
    if (tmp > MAXW) break;
    arr[i] = tmp;
    tmp *= w;
  }
  idx = i;
  long long sum = 0;
  for (__typeof(0) j = 0; j != idx; j++) {
    dif[j] = arr[j] - sum;
    sum += arr[j];
  }
  cout << (rec(m) ? "YES" : "NO") << endl;
  return 0;
}
