#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn];
int main() {
  int w, m, i, j, k, x, y, z, cnt;
  bool flag;
  while (scanf("%d%d", &w, &m) != EOF) {
    cnt = 0;
    memset(a, 0, sizeof(a));
    while (m) {
      a[cnt++] = m % w;
      m /= w;
    }
    flag = true;
    for (i = 0; i <= cnt; i++) {
      if (a[i] != 0 && a[i] != 1 && a[i] != w - 1 && a[i] != w) {
        flag = false;
        break;
      }
      if (a[i] == w - 1 || a[i] == w) {
        a[i + 1]++;
      }
    }
    if (flag)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
