#include <bits/stdc++.h>
using namespace std;
long long a[10000];
int main() {
  long long w, m;
  cin >> w >> m;
  int len = 0;
  if (w == 2) {
    cout << "YES" << endl;
    return 0;
  }
  while (m > 0) {
    a[len++] = m % w;
    m /= w;
  }
  int i = 0;
  long long f = 0;
  while (i < len || f) {
    a[i] += f;
    f = a[i] / w;
    a[i] %= w;
    if (a[i] == w - 1) {
      f++;
      a[i] = 0;
    } else if (a[i] > 1) {
      cout << "NO" << endl;
      return 0;
    }
    i++;
  }
  cout << "YES" << endl;
  return 0;
}
