#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
int w, m, bit[N];
bool work() {
  int cnt = 0;
  while (m) {
    bit[cnt++] = m % w;
    m /= w;
  }
  for (int i = 0; i < cnt; i++) {
    if (bit[i] <= 1) {
      continue;
    } else if (bit[i] == w - 1) {
      bit[i] = w;
      for (int j = i;; j++) {
        if (bit[j] == w) {
          bit[j + 1]++;
          bit[j] = 0;
        } else {
          break;
        }
      }
    } else {
      return false;
    }
  }
  return true;
}
int main() {
  scanf("%d%d", &w, &m);
  puts(work() ? "YES" : "NO");
  return 0;
}
