#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9, mod = 1e9 + 7, N = 1e5 + 9;
long long g[100], sz;
long long w, m;
void change() {
  while (m >= w) {
    g[sz++] = (m % w);
    m /= w;
  }
  g[sz++] = m;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> w >> m;
  change();
  bool flag = 1;
  for (int i = 0; i < 100; i++) {
    if (g[i] != 0 && g[i] != 1 && g[i] != w - 1 && g[i] != w) {
      flag = 0;
      break;
    }
    if (g[i] == w - 1) {
      g[i + 1]++;
      g[i] = 0;
    }
    if (g[i] == w) {
      g[i + 1]++;
      g[i] = 1;
    }
  }
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
}
