#include <bits/stdc++.h>
using namespace std;
long long w, m;
int d[200];
bool was[200];
int main() {
  std ::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> w >> m;
  long long x = m;
  int n = 0;
  while (x > 0) {
    d[n++] = x % w;
    x /= w;
  }
  memset(was, true, sizeof(was));
  bool ok = true;
  int last = 0;
  for (int i = 0; i <= n + 3; i++) {
    last = last + d[i];
    d[i] = last % w;
    last /= w;
    d[i] %= w;
    if (d[i] == 0) continue;
    if (d[i] == 1) {
      continue;
    }
    if ((d[i] + 1) % w != 0) {
      ok = false;
      break;
    }
    last = 1;
  }
  if (ok)
    puts("YES");
  else
    puts("NO");
  return 0;
}
