#include <bits/stdc++.h>
using namespace std;
long long int w, m;
long long int func(long long int n) {
  while (n) {
    if ((n % w) > 1) return 0;
    n /= w;
  }
  return 1;
}
void solve() {
  cin >> w >> m;
  long long int l = ceil(log(m) / log(w)) + 1;
  long long int tot = pow(2, l);
  for (long long int i = 0; i < tot; i++) {
    long long int val = m, cnt = 0, x = i;
    while (x) {
      if (x & 1) val += pow(w, cnt);
      x >>= 1;
      cnt++;
    }
    if (func(val)) {
      cout << "YES";
      exit(0);
    }
  }
  cout << "NO";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int qc = 1;
  for (long long int i = 1; i <= qc; i++) solve();
}
