#include <bits/stdc++.h>
using namespace std;
int a[200];
int w, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> w >> m;
  int k = 0;
  while (m > 0) {
    a[k] = m % w;
    m /= w;
    k++;
  }
  for (int i = 0; i < k + 5; i++) {
    if (a[i] == w - 1 || a[i] == w) {
      a[i + 1]++;
    } else if (a[i] != 0 && a[i] != 1) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
