#include <bits/stdc++.h>
using namespace std;
long long a[110];
int w, m, top;
int main() {
  scanf("%d%d", &w, &m);
  if (w == 2) {
    printf("YES");
    return 0;
  }
  a[1] = 1;
  for (int i = 2;; ++i) {
    a[i] = a[i - 1] * w;
    if (a[i] >= m) {
      top = i;
      break;
    }
  }
  long long t1 = 0, t2 = m;
  for (int i = 1; i <= top; ++i) {
    if (i != top) {
      long long t3 = t1 % a[i + 1] - t2 % a[i + 1];
      if (t3 == 0) continue;
      if (t3 == -a[i] || t3 == a[i + 1] - a[i]) {
        t1 += a[i];
        continue;
      }
      if (t3 == a[i] || t3 == -a[i + 1] + a[i]) {
        t2 += a[i];
        continue;
      }
      printf("NO");
      return 0;
    } else {
      long long t3 = t1 - t2;
      if (t3 == 0 || t3 == a[i] || t3 == -a[i]) {
        printf("YES");
        return 0;
      }
      printf("NO");
      return 0;
    }
  }
  return 0;
}
