#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, m;
  long long a[100005] = {0};
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> m >> n;
  k = 0;
  while (n >= 1) {
    k++;
    a[k] = n % m;
    n /= m;
  }
  bool z = 0;
  for (long long i = 1; i <= k; i++) {
    if (a[i] != 0 && a[i] != 1) {
      a[i] -= m;
      if (a[i] != -1 && a[i] != 0) {
        z = 1;
        break;
      }
      a[i + 1]++;
      if (i + 1 > k) k++;
    }
  }
  if (z == 0)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
