#include <bits/stdc++.h>
using namespace std;
int main() {
  int w, m, base[101], pos;
  cin >> w >> m;
  if (w == 2 || w == 3) {
    cout << "YES\n";
  } else {
    pos = 0;
    while (m > 0) {
      base[pos++] = m % w;
      m = m / w;
    }
    for (int i = 0; i < pos; i++) {
      if (base[i] == 0 || base[i] == 1) {
        continue;
      } else if (base[i] == w - 1 || base[i] == w) {
        base[i + 1]++;
      } else {
        cout << "NO\n";
        exit(0);
      }
    }
    cout << "YES\n";
  }
  return 0;
}
