#include <bits/stdc++.h>
using namespace std;
int a[111];
int n, m, w;
int main() {
  scanf("%d%d", &w, &m);
  while (m) {
    a[n++] = m % w;
    m /= w;
  }
  for (int i = 0; i < 50; i++) {
    if (a[i] >= w) {
      a[i + 1] += a[i] / w;
      a[i] %= w;
    }
    if (a[i] <= 1) continue;
    if (a[i] < w - 1) {
      printf("NO\n");
      return 0;
    }
    a[i + 1]++;
  }
  printf("YES\n");
  return 0;
}
