#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 1e2 + 10;
const long long MAX = 1e18;
template <typename T>
T gcd(T x, T y) {
  return y == 0 ? x : gcd(y, x % y);
}
template <typename T>
T lcm(const T &a, const T &b) {
  return (a * b) / gcd(a, b);
}
template <typename T>
void pfact(vector<pair<T, T> > &v, T k) {
  T i;
  for (i = 2; i <= sqrt(k); i++)
    if (k % i == 0) {
      T x = 0;
      while (k % i == 0) {
        k /= i;
        x++;
      }
      v.push_back(make_pair(i, x));
    }
  if (k != 1) {
    v.push_back(make_pair(k, 1));
  }
}
void sieve(int *spf) {
  spf[1] = 1;
  for (int i = 2; i < N; i++) spf[i] = i;
  for (int i = 4; i < N; i += 2) spf[i] = 2;
  for (int i = 3; i * i < N; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < N; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
vector<int> getFactorization(int x, int *spf) {
  vector<int> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x = x / spf[x];
  }
  return ret;
}
int main() {
  long long i, j, n, w, m;
  cin >> w >> m;
  vector<long long> v;
  while (m) {
    v.push_back(m % w);
    m /= w;
  }
  v.push_back(0);
  for (i = 0; i < v.size() - 1; i++) {
    if (v[i] == 0 || v[i] == 1) {
      continue;
    } else if (v[i] == (w - 1) || v[i] == (w)) {
      v[i + 1] += 1;
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
