#include <bits/stdc++.h>
using namespace std;
set<int> ap;
const int maxN = 30;
long long a[maxN], x[maxN], D[maxN];
long long b[10000000];
int n, k, X;
void tim(int i) {
  for (int j = 0; j <= 1; j++) {
    x[i] = j;
    if (j == 1) X = X + a[i];
    if (i == k) {
      n++;
      b[n] = X;
      ap.insert(X);
    } else
      tim(i + 1);
    if (j == 1) X = X - a[i];
  }
}
bool ktra(long long x) {
  if (ap.count(x))
    return true;
  else
    return false;
}
int main() {
  long long w, m;
  cin >> w >> m;
  if (w == 2) {
    cout << "YES";
    return 0;
  }
  k = 1;
  a[1] = 1;
  n = 0;
  while (a[k] < m) {
    k++;
    a[k] = a[k - 1] * w;
  };
  D[0] = 0;
  tim(1);
  sort(b + 1, b + n + 1);
  bool check = false;
  for (int i = 1; i <= n; i++) {
    if (b[i] == m) {
      check = true;
      break;
    };
    if (b[i] - m > 0)
      if (ktra(b[i] - m)) {
        check = true;
        break;
      };
  }
  if (check)
    cout << "YES";
  else
    cout << "NO";
}
