#include <bits/stdc++.h>
using namespace std;
long long w, m;
long long a[105];
long long b[105];
void read() { cin >> w >> m; }
void solve() {
  long long v = 1LL;
  int j = 0;
  for (int i = 0; i <= 100; ++i) {
    if (m < v) break;
    j = i;
    v *= w;
  }
  for (int i = j; i >= 0; --i) {
    m %= v;
    v /= w;
    a[i] = m / v;
  }
  for (int i = 0; i <= j + 1; ++i) {
    if (a[i] == 0 || a[i] == 1) continue;
    if (a[i] == w - 1) {
      a[i + 1]++;
      int x = i + 1;
      while (a[x] == w) {
        a[x] = 0;
        a[++x]++;
      }
      continue;
    }
    cout << "NO" << endl;
    return;
  }
  cout << "YES" << endl;
}
int main() {
  read();
  solve();
  return 0;
}
