#include <bits/stdc++.h>
using namespace std;
const int inf = 0xfffffff;
const int Mod = 1000000007;
int p[111];
int main() {
  long long w, m;
  int n = 0;
  cin >> w >> m;
  while (m) {
    p[n++] = m % w;
    m /= w;
  }
  for (int i = 0; i < n + 2; i++) {
    if (p[i] == w)
      p[i + 1]++;
    else if (p[i] == 0 || p[i] == 1) {
      continue;
    } else if (p[i] == w - 1) {
      p[i + 1]++;
    } else {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
