#include <bits/stdc++.h>
using namespace std;
long long bit[105];
int main() {
  long long w, m;
  cin >> w >> m;
  int cnt = 0;
  while (m) {
    bit[cnt++] = m % w;
    m /= w;
  }
  for (int i = 0; i < cnt; i++) {
    if (bit[i] >= w) {
      bit[i] -= w;
      bit[i + 1]++;
    }
    if (bit[i] == w - 1) {
      bit[i] = 0;
      bit[i + 1]++;
    } else {
      if (bit[i] > 1) {
        printf("NO\n");
        return 0;
      }
    }
  }
  cout << "YES" << endl;
}
