#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
const long long sz = 1e9 + 7;
long long gcd(long long n, long long m) {
  while (n) swap(n, m), n %= m;
  return m;
}
long long power(long long a, long long b) {
  a %= sz;
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % sz;
    a = (a * a) % sz;
    b >>= 1;
  }
  return res;
}
long long modInverse(long long a) { return power(a, sz - 2); }
vector<long long> f(41);
bool check() {
  for (long long i = 0; i < 41; i++) {
    if (f[i] > 1) return false;
  }
  return true;
}
void solve() {
  long long w, m;
  cin >> w >> m;
  long long i = 0;
  while (m != 0) {
    f[i] = m % w;
    m /= w;
    i++;
  }
  if (check())
    cout << "YES" << '\n';
  else {
    long long i = 0;
    bool ok = true;
    while (i < 41) {
      if (f[i] == 0)
        i++;
      else if (f[i] == 1)
        i++;
      else if (f[i] == w - 1) {
        while ((f[i] == w - 1 || f[i] == w - 2) && i < 101) i++;
        if (f[i] != 0) {
          ok = false;
          break;
        } else
          i++;
      } else {
        ok = false;
        break;
      }
    }
    if (ok)
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
  }
}
int32_t main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  ;
  long long T = 1;
  for (long long i = 1; i < T + 1; i++) {
    solve();
  }
}
