#include <bits/stdc++.h>
using namespace std;
int w, m, v[105], flag = 0;
int main() {
  scanf("%d%d", &w, &m);
  memset(v, 0, sizeof(v));
  int q = w, temp = m, k = 0;
  while (temp != 0) {
    v[k] = temp % q;
    temp /= q;
    k++;
  }
  for (int i = 0; i <= 100; i++) {
    v[i + 1] += v[i] / w;
    v[i] = v[i] % w;
    if (v[i] == w - 1 && v[i] != 1 && i + 1 <= 100) {
      v[i] = -1;
      v[i + 1]++;
    }
  }
  for (int i = 0; i <= 100; i++) {
    if (v[i] != 1 && v[i] != 0 && v[i] != -1) {
      flag = 1;
      break;
    }
  }
  if (flag == 0)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
