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