#include <bits/stdc++.h>
using namespace std;
int w, m, a[50];
int main(void) {
  int i, j;
  while (~scanf("%d%d", &w, &m)) {
    int num = 0;
    memset(a, 0, sizeof(a));
    while (m) {
      a[num++] = m % w;
      m /= w;
    }
    int ok = 1;
    for (i = 0; i <= num; i++) {
      if (a[i] == 0 || a[i] == 1) continue;
      if (a[i] == w - 1) {
        a[i + 1]++;
        continue;
      }
      if (a[i] == w) {
        a[i + 1]++;
        continue;
      }
      ok = 0;
      break;
    }
    printf("%s\n", ok ? "YES" : "NO");
  }
  return 0;
}
