#include <bits/stdc++.h>
int main() {
  int w, m;
  scanf("%d%d", &w, &m);
  bool good = true;
  while (m) {
    int d = m % w;
    m /= w;
    if (d == 0 || d == 1) {
      continue;
    } else if (d == w - 1) {
      m++;
      continue;
    } else {
      good = false;
      break;
    }
  }
  printf(good ? "YES\n" : "NO\n");
  return 0;
}
