#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n, w;
  cin >> w >> n;
  vector<long long> v(100);
  long long size = 0;
  while (n != 0) {
    v[size] = n % w;
    n /= w;
    size++;
  }
  long long f = 0;
  for (long long i = 0; i <= size; i++) {
    if (v[i] == 0 || v[i] == 1) {
      continue;
    }
    if (v[i] - w >= -1) {
      v[i + 1]++;
    } else {
      f = 1;
      break;
    }
  }
  if (f) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
  }
  return 0;
}
